curl --location 'https://api.gugudata.com/imagerecognition/pdf2format?appkey={{appkey}}&type={{type}}' \
--form 'pdffile=@"localfile_path.png"'
CURL *curl;
CURLcode res;
curl = curl_easy_init();
if(curl) {
curl_easy_setopt(curl, CURLOPT_CUSTOMREQUEST, "POST");
curl_easy_setopt(curl, CURLOPT_URL, "https://api.gugudata.com/imagerecognition/pdf2format?appkey={{appkey}}&type={{type}}");
curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L);
curl_easy_setopt(curl, CURLOPT_DEFAULT_PROTOCOL, "https");
struct curl_slist *headers = NULL;
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers);
curl_mime *mime;
curl_mimepart *part;
mime = curl_mime_init(curl);
part = curl_mime_addpart(mime);
curl_mime_name(part, "pdffile");
curl_mime_filedata(part, "localfile_path.png");
curl_easy_setopt(curl, CURLOPT_MIMEPOST, mime);
res = curl_easy_perform(curl);
curl_mime_free(mime);
}
curl_easy_cleanup(curl);
var formdata = new FormData();
formdata.append("pdffile"), fileInput.files[0], "localfile_path.png");
var requestOptions = {
method: 'POST',
body: formdata,
redirect: 'follow'
};
fetch("https://api.gugudata.com/imagerecognition/pdf2format?appkey={{appkey}}&type={{type}}", requestOptions)
.then(response => response.text())
.then(result => console.log(result))
.catch(error => console.log('error', error));
var options = new RestClientOptions("https://api.gugudata.com")
{
MaxTimeout = -1,
};
var client = new RestClient(options);
var request = new RestRequest("/imagerecognition/pdf2format?appkey={{appkey}}&type={{type}}", Method.Post);
request.AlwaysMultipartFormData = true;
request.AddFile(pdffile, "localfile_path.png");
RestResponse response = await client.ExecuteAsync(request);
Console.WriteLine(response.Content)
package main
import (
"fmt"
"bytes"
"mime/multipart"
"os"
"path/filepath"
"io"
"net/http"
"io/ioutil"
)
func main() {
url := "https://api.gugudata.com/imagerecognition/pdf2format?appkey={{appkey}}&type={{type}}"
method := "POST"
payload := &bytes.Buffer{}
writer := multipart.NewWriter(payload)
file, errFile1 := os.Open("localfile_path.png")
defer file.Close()
part1,
errFile1 := writer.CreateFormFile("pdffile",filepath.Base("localfile_path.png"))
_, errFile1 = io.Copy(part1, file)
if errFile1 != nil {
fmt.Println(errFile1)
return
}
err := writer.Close()
if err != nil {
fmt.Println(err)
return
}
client := &http.Client {
}
req, err := http.NewRequest(method, url, payload)
if err != nil {
fmt.Println(err)
return
}
req.Header.Set("Content-Type", writer.FormDataContentType())
res, err := client.Do(req)
if err != nil {
fmt.Println(err)
return
}
defer res.Body.Close()
body, err := ioutil.ReadAll(res.Body)
if err != nil {
fmt.Println(err)
return
}
fmt.Println(string(body))
}
OkHttpClient client = new OkHttpClient().newBuilder().build();
MediaType mediaType = MediaType.parse("text/plain");
RequestBody body = new MultipartBody.Builder().setType(MultipartBody.FORM).addFormDataPart("pdffile","localfile_path.png",
RequestBody.create(MediaType.parse("application/octet-stream"),
new File("localfile_path.png"))).build();
Request request = new Request.Builder()
.url("https://api.gugudata.com/imagerecognition/pdf2format?appkey={{appkey}}&type={{type}}")
.method("POST", body).build();
Response response = client.newCall(request).execute();
var form = new FormData();
form.append("pdffile", fileInput.files[0], "localfile_path.png");
var settings = {
"url": "https://api.gugudata.com/imagerecognition/pdf2format?appkey={{appkey}}&type={{type}}",
"method": "POST",
"timeout": 0,
"processData": false,
"mimeType": "multipart/form-data",
"contentType": false,
"data": form
};
$.ajax(settings).done(function (response) {
console.log(response);
});
#import <Foundation/Foundation.h>
dispatch_semaphore_t sema = dispatch_semaphore_create(0);
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:@"https://api.gugudata.com/imagerecognition/pdf2format?appkey={{appkey}}&type={{type}}"]
cachePolicy:NSURLRequestUseProtocolCachePolicy
timeoutInterval:10.0];
NSArray *parameters = @[@{ @"name": @"pdffile", @"fileName": @"localfile_path.png" } ];
NSString *boundary = @"----WebKitFormBoundary7MA4YWxkTrZu0gW";
NSError *error;
NSMutableString *body = [NSMutableString string];
for (NSDictionary *param in parameters) {
[body appendFormat:@"--%@\r\n", boundary];
if (param[@"fileName"]) {
[body appendFormat:@"Content-Disposition:form-data; name=\"%@\"; filename=\"%@\"\r\n", param[@"name"], param[@"fileName"]];
[body appendFormat:@"Content-Type: %@\r\n\r\n", param[@"contentType"]];
[body appendFormat:@"%@", [NSString stringWithContentsOfFile:param[@"fileName"] encoding:NSUTF8StringEncoding error:&error]];
if (error) {
NSLog(@"%@", error);
}
} else {
[body appendFormat:@"Content-Disposition:form-data; name=\"%@\"\r\n\r\n", param[@"name"]];
[body appendFormat:@"%@", param[@"value"]];
}
}
[body appendFormat:@"\r\n--%@--\r\n", boundary];
NSData *postData = [body dataUsingEncoding:NSUTF8StringEncoding];
[request setHTTPBody:postData];
[request setHTTPMethod:@"POST"];
NSURLSession *session = [NSURLSession sharedSession];
NSURLSessionDataTask *dataTask = [session dataTaskWithRequest:request
completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) {
if (error) {
NSLog(@"%@", error);
dispatch_semaphore_signal(sema);
} else {
NSHTTPURLResponse *httpResponse = (NSHTTPURLResponse *) response;
NSError *parseError = nil;
NSDictionary *responseDictionary = [NSJSONSerialization JSONObjectWithData:data options:0 error:&parseError];
NSLog(@"%@",responseDictionary);
dispatch_semaphore_signal(sema);
}
}];
[dataTask resume];
dispatch_semaphore_wait(sema, DISPATCH_TIME_FOREVER);
import requests
url = "https://api.gugudata.com/imagerecognition/pdf2format?appkey={{appkey}}&type={{type}}"
payload={}
files=[('imagefile',(' pdffile',open('localfile_path.png','rb'),'image/png'))]
headers = {}
response = requests.request("POST", url, headers=headers, data=payload, files=files)
print(response.text)
require "uri"
require "net/http"
url = URI("https://api.gugudata.com/imagerecognition/pdf2format?appkey={{appkey}}&type={{type}}")
https = Net::HTTP.new(url.host, url.port)
https.use_ssl = true
request = Net::HTTP::Post.new(url)
form_data = [['pdffile', File.open('localfile_path.png')]]
request.set_form form_data, 'multipart/form-data'
response = https.request(request)
puts response.read_body
let parameters = [["key": "pdffile",
"src": "localfile_path.png",
"type": "file"]] as [[String: Any]]
let boundary = "Boundary-\(UUID().uuidString)"
var body = ""
var error: Error? = nil
for param in parameters {
if param["disabled"] != nil { continue }
let paramName = param["key"]!
body += "--\(boundary)\r\n"
body += "Content-Disposition:form-data; name=\"\(paramName)\""
if param["contentType"] != nil {
body += "\r\nContent-Type: \(param["contentType"] as! String)"
}
let paramType = param["type"] as! String
if paramType == "text" {
let paramValue = param["value"] as! String
body += "\r\n\r\n\(paramValue)\r\n"
} else {
let paramSrc = param["src"] as! String
let fileData = try NSData(contentsOfFile: paramSrc, options: []) as Data
let fileContent = String(data: fileData, encoding: .utf8)!
body += "; filename=\"\(paramSrc)\"\r\n"
+ "Content-Type: \"content-type header\"\r\n\r\n\(fileContent)\r\n"
}
}
body += "--\(boundary)--\r\n";
let postData = body.data(using: .utf8)
var request = URLRequest(url: URL(string: "https://api.gugudata.com/imagerecognition/pdf2format?appkey={{appkey}}&type={{type}}")!,timeoutInterval: Double.infinity)
request.addValue("multipart/form-data; boundary=\(boundary)", forHTTPHeaderField: "Content-Type")
request.httpMethod = "POST"
request.httpBody = postData
let task = URLSession.shared.dataTask(with: request) { data, response, error in
guard let data = data else {
print(String(describing: error))
return
}
print(String(data: data, encoding: .utf8)!)
}
task.resume()
var request = require('request');
var fs = require('fs');
var options = {
'method': 'POST',
'url': 'https://api.gugudata.com/imagerecognition/pdf2format?appkey={{appkey}}&type={{type}}',
'headers': {
},
formData: {
'pdffile': {
'value': fs.createReadStream('localfile_path.png'),
'options': {
'filename': 'localfile_path.png',
'contentType': null
}
}
}
};
request(options, function (error, response) {
if (error) throw new Error(error);
console.log(response.body);
});
<?php
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => 'https://api.gugudata.com/imagerecognition/pdf2format?appkey={{appkey}}&type={{type}}',
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => '',
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 0,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => 'POST',
CURLOPT_POSTFIELDS => array('pdffile'=> new CURLFILE('localfile_path.png')),
));
$response = curl_exec($curl);
curl_close($curl);
echo $response;