Upload file with a filename containing spaces

Having trouble figuring out what is need to successfully upload a file that contains spaces in the filename and also a directory that contains spaces. I’ve tried replaces the spaces with %20 but still am getting a 400 bad request response. What is the correct cURL syntax for this?

curl -H application-id:A7B…00 -H secret-key:655…00 -H Content-Type:“multipart/form-data” -H application-type:REST --form upload=@“my file is this.txt” -X POST -v “https://api.backendless.com/v1/files/Testfiles/myfile is this.txt”

curl -H application-id:A7B…00 -H secret-key:655…00 -H Content-Type:“multipart/form-data” -H application-type:REST --form upload=@“my file is this.txt” -X POST -v “https://api.backendless.com/v1/files/Test files/myfile is this.txt”

Try the suggestion in this thread:

The documented you pointed to help with spaces in the input filename but what I don’t know is how to format the URL that contains spaces in either the directory name or the file that will be created as a result of the REST API call.

Can you point me to a solution?

Here’s a curl request I just tried:

curl -H application-id:MYAPPID -H secret-key:RESTSECRETKEY -H Content-type:“multipart/form-data” --form upload=@test.txt -X POST -v “http://api.backendless.com/v1/files/txtfiles/dir%20with%20spaces/test.txt

Here’s the response from the server:

{“fileURL”:“https://api.backendless.com/31cb9fed-f34c-5541-ff26-6c2b6719f200/v1/files/txtfiles/dir+with+spaces/test.txt”}

Here’s the created directory (as seen in console):
http://support.backendless.com/public/attachments/f2f903a995015dab1ed12d9125141d3b.jpg</img>

I tried your exact curl command and I didn’t get the same results. Below is the request and response. I would like to be able to support REST API calls to upload a file with a filename and/or with spaces.

http://support.backendless.com/public/attachments/89aa47c3ec688092003006e844124a7d.jpg</img>

Sorry, I posted the snapshot of a request with the file already uploaded. Here is the clean request response. I tried the URL enclosed with quotes like you had and also got the same response.

http://support.backendless.com/public/attachments/9edf0b11ed391d3d7d63c5e8444c7bd4.jpg</img>

Trying to figure out the necessary encoding in order to upload a file to a directory that contains spaces in its name.

The following curl command doesn’t work for me. The response contains the directory name - …/txtfiles/dir0with0spaces/test.txt. NOTE: The directory in Backendless didn’t exist prior to the curl call.

curl -H application-id:APPID -H secret-key:SECRET_KEY -H Content-type:“multipart/form-data” --form upload=@myfileisthis.txt -X POST -v “http://api.backendless.com/v1/files/txtfiles/dir%20with%20spaces/test.txt

In this I created the directory first in Backendless. The response in this case is:
{“fileURL”:“https://api.backendless.com/a7b8f6e8-1688-922f-ffb7-6dac5cae6c00/v1/files/txtfiles/dir1+with+spaces/test.txt”}

curl -H application-id:A7B8F6E8-1688-922F-FFB7-6DAC5CAE6C00 -H secret-key:655E37FB-70D0-53E8-FF5D-ABBBE7720800 -H Content-type:“multipart/form-data” --form upload=@myfileisthis.txt -X POST -v “http://api.backendless.com/v1/files/txtfiles/dir1 with spaces/test.txt”

Request using ‘+’ in URL for spaces in directory

curl -H application-id:A7B8F6E8-1688-922F-FFB7-6DAC5CAE6C00 -H secret-key:SKEY -H Content-type:“multipart/form-data” --form upload=@myfileisthis.txt -X POST -v "http://api.backendless.com/v1/files/txtfiles/dir2+with+spaces/test.txt";

Response:

{“fileURL”:"https://api.backendless.com/a7b8f6e8-1688-922f-ffb7-6dac5cae6c00/v1/files/txtfiles/dir2%2Bwith%2Bspaces/test.txt";}

So you can use both %20 and + for whitespaces, right?

I can use the %20 and + but the response should contain the spaces also. In addition, the directory that is actually created by the request should reflect the spaces in the directory name.