上传一个图像服务,可以称为一个POST请求以下网址:
[文章]https://azure.leadtools.com/api/UploadFile
请求特定的参数
下面列出了可用的附加参数。
参数 | 描述 | 接受的价值观 |
---|---|---|
ImageUrl (可选) |
要处理的文件的URL。有关更多信息,请参阅云服务概述部分。 | 一个字符串或文件URI包含一个有效的URL。 |
状态码
以下将返回状态代码调用方法时:
状态 | 描述 |
---|---|
200年 | 文件已成功上传 |
400年 | 请求未能有效以下原因之一: * AppId /密码没有提供 *文件提供的信息是畸形的。 |
401年 | AppID /密码组合是无效的,或不符合提供的GUID。 |
返回
一个成功的请求将返回一个GUID对应上传文件。可以使用该GUID排队服务请求,除了用于查询您的文件的状态。
例子
/ /这个示例使用请求NodeJs图书馆。const请求=要求(“请求”);var servicesUrl = " https://azure.leadtools.com/api/ ";var fileURL = ' https://demo.leadtools.com/images/pdf/leadtools.pdf ';var uploadUrl = servicesUrl +“还是?fileurl = " + fileurl;request.post (getRequestOptions (uploadUrl) uploadCallback);函数uploadCallback(误差、响应、身体){如果!& &错误响应。statusCode = = 200) {guid =身体;控制台。日志(“惟一的ID返回的服务:”+ guid); }else{ console.log("Failed to upload file with status code: " + response.statusCode); } } function getRequestOptions(url){ //Function to generate and return HTTP request options. var requestOptions ={ url: url, headers: { 'Content-Length' : 0 }, auth: { user:"Enter Application ID", password:"Enter Application Password" } }; return requestOptions; }
使用系统;使用来;使用text;使用System.Threading.Tasks;使用System.Threading;使用System.Net;使用System.Net.Http;使用System.Net.Http.Headers;使用Newtonsoft.Json.Linq;名称空间Azure_Code_Snippets。DocumentationSnippets { class CloudServices_UploadFile_Demo { private string hostedServicesUrl = "https://azure.leadtools.com/api/"; public async void UploadImage() { string fileURL = "https://demo.leadtools.com/images/pdf/leadtools.pdf"; string uploadUrl = string.Format("UploadFile?fileurl={0}", fileURL); var client = InitClient(); var result = await client.PostAsync(uploadUrl, null); if (result.StatusCode == HttpStatusCode.OK) { //Unique ID returned by the services string id = await result.Content.ReadAsStringAsync(); Console.WriteLine("Unique ID returned by the services: " + id); } else Console.WriteLine("Request failed with the following response: " + result.StatusCode); } private HttpClient InitClient() { string AppId = "Enter Application ID"; string Password = "Enter Application Password"; HttpClient client = new HttpClient(); client.BaseAddress = new Uri(hostedServicesUrl); client.DefaultRequestHeaders.Accept.Clear(); client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json")); string authData = string.Format("{0}:{1}", AppId, Password); string authHeaderValue = Convert.ToBase64String(Encoding.UTF8.GetBytes(authData)); client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", authHeaderValue); return client; } } }
#这个示例使用python库的请求。进口的请求,系统,时间servicesUrl = ' https://azure.leadtools.com/api/ ' fileURL = ' https://demo.leadtools.com/images/pdf/leadtools.pdf ' #应用程序ID. appId =“输入应用程序ID”;#应用程序密码。密码= "输入应用程序密码”;baseUploadUrl = '{}还是?fileurl = {} ' formattedUploadUrl = baseUploadUrl。格式(servicesUrl fileURL)请求=请求。帖子(formattedUploadUrl auth = (appId、密码))如果请求。status_code ! = 200:打印(“错误发送转换请求”)打印(request.text) sys.exit() #的文件已经成功上传。现在我们已经GUID,我们可以使用它来排队的请求文件GUID =请求。文本打印(“惟一的ID返回的服务:”+ guid)
< ?php servicesBaseUrl美元= " https://azure.leadtools.com/api/ ";美元fileURL = ' https://demo.leadtools.com/images/pdf/leadtools.pdf ';uploadUrl美元= " % sUploadFile ? fileurl = % s”;$ uploadUrl = sprintf ($ uploadUrl servicesBaseUrl美元fileURL美元);(requestOptions = GeneratePostOptions美元uploadUrl);$请求= curl_init ();curl_setopt_array(请求,requestOptions美元);如果(!$ guid = curl_exec(请求)美元)/ /确保请求成功{如果(curl_errno(请求)美元){回声”有一个错误队列请求\ n \ r”; echo curl_error($request); curl_close($request); return false; } } curl_close($request); //The request completed successfully. Now that we have the GUID, we can use it to queue up requests for the file. echo "Unique ID returned by the services: $guid \n"; function GeneratePostOptions($url) { $appId = "Enter Application ID"; $password = "Enter Application Password"; $headers = array( "Content-Length : 0" ); $postOptions = array( CURLOPT_POST => 1, CURLOPT_URL => $url, CURLOPT_FRESH_CONNECT => 1, CURLOPT_RETURNTRANSFER => 1, CURLOPT_USERPWD => "$appId:$password", CURLOPT_FORBID_REUSE => 1, CURLOPT_HTTPHEADER => $headers ); return $postOptions; } ?>
使用基本的HTTP:消息;使用LWP:: UserAgent ();我的美元servicesUrl = " https://azure.leadtools.com/api/ ";我的美元fileURL = ' https://demo.leadtools.com/images/pdf/leadtools.pdf ';我的美元appId =“输入应用程序ID”;我的密码美元=“输入应用程序密码”;我$ header = HTTP: header - >新(Content_Length = > 0);$头- > authorization_basic (appId美元,美元密码);#发出请求时使用的用户代理我$ ua = LWP:: UserAgent - >新;uploadUrl = servicesUrl美元。 'UploadFile?fileurl=' . $fileURL; my $request = HTTP::Request->new(POST => $uploadUrl , $headers); my $response = $ua->request($request); if(!$response->is_success){ print STDERR $response->status_line, "\n"; exit; } my $guid = $response->decoded_content; print("Unique ID returned by the services: " . $guid . "\n");