Upload one file

The maximum file size supported by the service is 100 MB.

If the file is empty, error code & string: 35017 - The uploaded file is empty.

HTTP REQUEST

POST

URL

https://cloud.dynamsoft.com/rest/ocr/v1.1/file

Request Parameters

Parameters Type If Mandatory Description
method string Yes Fixed value: upload
x-api-key string Yes DDC API Key. When making any API request, pass your key as the value of an x-api-key parameter in the Header.
file a part of "multipart/form-data" Yes File content.

Note:
1. The data construction of this parameter should conform to the W3C Specification and the Multipart Form RFC.
e.g.:

Content-Disposition: form-data; name="file"; filename="Code 93.png"
Content-Type: application/octet-stream

[raw binary data]

2. The value of filename cannot be empty, including \r, \n, \t, space, \0, \x0B, and cannot include invalid characters, e.g., <, >, :, etc.

ondup string No Behavior on duplicate. Default value is "Newcopy".
Overwrite: replace the file with the same filename;
Newcopy: create a new copy and rename the copy as "filename(0).type".

Note:
File need to be sent in POST form data. Ondup can be sent in query_string or POST data form.

Version 1.1 added support for uploading as base64. In the request payload, you can specify the content type as “text/plain” to indicate the data is base64.
e.g.:
Content-Disposition: form-data; name="file"; filename="Code 93.png"
Content-Type: text/plain

[base64 string]

Response Parameters

Parameters Type UrlEncode Description
file_name string No Filename returned from the server. If ondup is set as Newcopy, this value might be different from the original name.
size int32 No File size by byte
ctime int32 No File create time
mtime int32 No File modify time
md5 String No File md5 signature
error_code int32 No Error code
error_msg string No Error message
request_id string No Request ID
page_number int32 No No. of pages of the uploaded file

Sample Code
Request Body:

x-api-key: z81QwIA3kg0tUXkueP+QN4qXFCP0MIQIqDn94uxoVPdcnnGArr366w==
POST https://cloud.dynamsoft.com/rest/ocr/v1.1/file?method=upload

Response:

{
     'file_name': 'f1.jpg',
     'size': 372121,
     'ctime': 1234567890,
     'mtime': 1234567890,
     'md5': 'cb123afcc12453543ef',
     'page_number': 1,
     'error_code': 0,
     'error_msg': 'Success.',
     'request_id':3043312669
}
Is this page helpful?

Leave a Reply

Your email address will not be published.