Trying to upload file resulting with Empty response or curl: (26) couldn't open file
Hi All,
I am trying to use cURL command to upload a simple test file in Box and find out it is working fine. But, I am facing the following issue.
This is the command that i tried on Terminal on MacBook.
curl https://upload.box.com/api/2.0/files/content \
-H "Authorization: Bearer GdeRrUh3nm8VJCUzd3LEIGyyLWiyR2op" -X POST \
-F attributes='{"name":"test.txt", "parent":{"id":"0"}}' \
-F file=@test.txt
Nothing happened. Do I need to give full path for file?
If give it like below file full path like below,
curl https://upload.box.com/api/2.0/files/content \
-H "Authorization: Bearer GdeRrUh3nm8VJCUzd3LEIGyyLWiyR2op" -X POST \
-F attributes='{"name":"test.txt", "parent":{"id":"0"}}' \
-F file=@/Users/myuser/test.txt
then i get error "curl: (26) couldn't open file "/Users/myuser/test.txt" in Terminal
Any help please?
-
Ok, I had another update on the same query:
curl https://upload.box.com/api/2.0/files/content \
-H "Authorization: Bearer sfsfsdfsdfhghjhgjdsfsfsmUpQQN2ia" -X POST \
-F attributes='{"name":"test.txt", "parent":{"id":"123123123"}}' \
-F file=@test.txtResponse in Terminal on Mac:
{"type":"error","status":409,"code":"item_name_in_use","context_info":{"conflicts":{"type":"file","id":"60***phone number removed for privacy***","file_version":{"type":"file_version","id":"638521169833","sha1":"xxxxxxxyyyyyyzzzzzf763cce44574a5b5ab03"},"sequence_id":"0","etag":"0","sha1":"c0b137fe2d792459f26ff763cce44574a5b5ab03","name":"test.txt"}},"help_url":"http:\/\/developers.box.com\/docs\/#errors","message":"Item with the same name already exists","request_id":"kzynrtgb608vl1dw"}
But, there is NO file like that in box folder.
-
Hi ,
Typically this is due to the file being uploaded to another user / account than the one you're looking at. For instance, if you're using a JWT based application and auth as the enterprise, then the file would be uploaded to the service account, not your user account. If that's your application type then you can go to the content section of your admin console, then under users there should be a user with the same name as your app. Clicking on that will show whether the file went up there or not.
Basically I would recommend ensuring that your access token is scoped for the user that you're intending to upload to. You can also user the get current user endpoint call to verify the scope of the token.
- Jon
-
Yes, I am trying to upload to a service account created by my senior. I am testing this in Terminal as command on MacBook.
1. Do we need to use "parent" or "file" ID here? Because, looks like "file" id works fine.
curl https://upload.box.com/api/2.0/files/content \
-H "Authorization: Bearer jshdkjasdjkasdh832183" -X POST \
-F attributes='{"name":"test.txt", "parent":{"id":"111111111"}}' \
-F file=@test.txt2. Do we need to use full path URL or not?
-F attributes='{"name":"/Users/plo2771/test.txt", "parent":{"id":"111111111"}}'
or
-F attributes='{"name":"test.txt", "parent":{"id":"111111111"}}' \
if we use full path, it gives error "couldn't open file" , but the file is in read/write mode. I am using MacBook.
-
Hi ,
For #1, parent ID is required, and that will be the ID of the folder that the file should be uploaded into.
For #2, no, you don't need to use the full path. That name field is the name / extension that the file should be given when it is stored in Box, which may be different than the actual filename on the system you're uploading from.
- Jon
Please sign in to leave a comment.
Comments
4 comments