How to upload file/attachment using FileApiService

Hello,

 

I am trying to upload files as you would do manually in the browser, but using an API. When dragging and dropping a file into the attachments tabs of any section, I see in the browser that Creatio performs a POST request to its FileApiService with a format like the following example:

 

The endpoint is https://my-creatio-site.creatio.com/0/rest/FileApiService/UploadFile and the file content is passed in the request body.

 

In order to simulate this behavior, I am sending 2 requests:

 

  1. A POST request to create the file id allocating space in the File table:

  2. A POST request to https://my-creatio-site.creatio.com/0/rest/FileApiService/UploadFile using the file information to upload the actual file.

 

However as you can see, the 2nd request fails in my app with the following error:

{
  "errorInfo": {
    "errorCode": "InvalidFileSizeException",
    "message": "No se puede analizar el tamaño del archivo.",
    "stackTrace": "   at Terrasoft.Configuration.FileUpload.FileUploadInfo.get_TotalFileLength()\r\n   at Terrasoft.Configuration.FileUpload.FileUploader.UploadFile(IFileUploadConfig fileUploadInfoConfig)\r\n   at Terrasoft.Configuration.FileUpload.FileUploader.UploadFile(IFileUploadInfo fileUploadInfo, Boolean isSetCustomColumns)\r\n   at Terrasoft.Configuration.FileApiService.UploadFile(Stream fileContent)"
  },
  "success": false,
  "nextPrcElReady": false,
  "queryId": null,
  "responseStatus": {
    "ErrorCode": "InvalidFileSizeException",
    "Message": "No se puede analizar el tamaño del archivo.",
    "StackTrace": "   at Terrasoft.Configuration.FileUpload.FileUploadInfo.get_TotalFileLength()\r\n   at Terrasoft.Configuration.FileUpload.FileUploader.UploadFile(IFileUploadConfig fileUploadInfoConfig)\r\n   at Terrasoft.Configuration.FileUpload.FileUploader.UploadFile(IFileUploadInfo fileUploadInfo, Boolean isSetCustomColumns)\r\n   at Terrasoft.Configuration.FileApiService.UploadFile(Stream fileContent)",
    "Errors": null,
    "Meta": null
  },
  "rowsAffected": -1
}

 

I already ensured that the file size passed in both requests is exactly the same always (in this example is 584833 bytes) but I don't know what causes the error.

 

I already checked the following community posts but couldn't find any help:

 

 

Note: I tested these requests in many Creatio websites, all of them with version 8.2.0 

 

Regards.

Like 0

Like

2 comments

Hello again,

 

I just found a different community post:

https://community.creatio.com/questions/get-error-403-denied-when-uploading-file-filepiservice

 

After following the steps explained by @Ryan Farley I was able to upload files properly. My problem was that I was missing the following request headers:

 

  • Content-Range = bytes 0-{size in bytes - 1}/{size in bytes}
  • Content-Type = "application/octet-stream"

 

Thank you very much!

Glad you found the older post and have it working now!

Show all comments