Support Topics Documentation Slack YouTube Blog

File upload: '400' [HTTP 400] <bad request>

(Chris) #1

I’m getting the following error when I attempt to upload a png file to the database: ‘400’ [HTTP 400] <bad request>

This functionality has been working on my app for months and I havne’t made any code changes. I did recently change my back endless setup to add a new version of the database so now i have a v1(the first version created by default which Im using as my dev environment) and a production version. Could this be related to my file upload errors? I get errors when working in both environments.

 func uploadImage(image: NSData, imageTitle: String, completion:(BackendlessFile?, Fault?) -> Void)
 print("\n============ Uploading files with the ASYNC API ============")

 content: image,
 overwrite: true,
 response: { ( uploadedFile : BackendlessFile!) -> () in
 print("File has been uploaded. File URL is - \(uploadedFile.fileURL)")
 completion(uploadedFile, nil)
 error: { ( fault : Fault!) -> () in
 print("Server reported an error: \(fault)")
 completion(nil, fault)

(Chris) #2

I tried testing with the sample piece of code from your guide and got the same result, so this issue either must be on your end or somehow related to the db versions.

Heres the sample code that still gave me a 400 error, only change I made was to update println to print:

    func uploadAsync() {
        print("\n============ Uploading files with the ASYNC API ============")
        var data = NSData(bytes:"Hello mbaas!\nUploading files is easy!", length:37)
        backendless.fileService.upload("myfiles/myhelloworld-async.txt", content: data,
                                       response: { (var uploadedFile : BackendlessFile!) -> () in
                                        print("File has been uploaded. File URL is - \(uploadedFile.fileURL)")
                                       error: { (var fault : Fault!) -> () in
                                        print("Server reported an error: \(fault)")

(Chris) #3

Found a fix… if I use:


instead of:


it works.

Not sure what would have changed to make this happen. Would appreciate an explanation for why I needed to change the syntax - thanks!

(Chris) #4

You marked this as solved but I’d like an explanation for why i needed to make an update

(Sergey Chupov) #5

Hi Chris,

We shall test both methods and notify you about the results when available. Sorry for the inconvenience!

(Chris) #6

Any updates on this? Using the previous function I was able to overwrite the existing file, the new function doesn’t allow overwrites and is causing problems in my app.

(Marcio Prudencio) #7

Hey guys, I’m also getting a bad request uploading a single file. Any idea about what’s is wrong here?
*Using react-native component, selecting the picture just fine…

(Vladimir Upirov) #8

Hi Marcio

There is should be an error message from the server, it can give us more details, can you see that?

I’m not sure but I guess there is must be FormData, but maybe axios already does it, and also according to our JS-SDK we use “file” form field for transferring a file to the server

Can you provide a code snippet which we can use for reproducing your issue?

Regards, Vlad

(Marcio Prudencio) #9

Hi Vladimir, thanks for your support. As you mentioned I did some digging and I found a way to get extra message from Axios, and now I could see here is something related with React.

message: “Corrupted multipart request. Header Content-Type must be set to value multipart/form-data”

Found solution:

Thanks for your help!

(Vladimir Upirov) #10

Thank you for sharing the solution, I believe it will be helpful for other developers