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.
code
func uploadImage(image: NSData, imageTitle: String, completion:(BackendlessFile?, Fault?) -> Void)
{
print("\n============ Uploading files with the ASYNC API ============")
backendless.fileService.upload(
"myfiles/test.png",
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)
})
}
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)")
}
)
}
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.
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…
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”