sbtools icon indicating copy to clipboard operation
sbtools copied to clipboard

item_upload_create only posts the first file

Open jordansread opened this issue 11 years ago • 6 comments

when using multi-file post

jordansread avatar Mar 06 '15 16:03 jordansread

I think this is the way this service is supposed to work, as it posts a file and creates an item to contain it. Should probably only have file (instead of files) as the param. Change documentation and warn if length(file)!=1?

jordansread avatar Mar 06 '15 16:03 jordansread

Ah, this is a super complicated issue.

Notes for future reference:

SB can handle multiple files for this type of upload. File upload and update and upload and create seem to be very similar endpoints. Having issues uploading multiple files may be a fluke, as I can get both to work with most files. But I can also get both to fail even with just one file. This example kills both item_append_files and item_upload_create.

OMG Why?

Must be encoding of some sort. One of the big puzzles is how much "Content-Transfer-Encoding:binary" matters in the multi-file upload. I am fairly certain I can't add that to the uploads using httr or RCurl. Furthermore, it seems to be a part of MIME protocol standards, not HTTP, as discussed here and mentioned in RFC2616 19.4.5. This may be the reason I am generally unable to add that particular header with most HTTP clients I've used.

The general pattern I've been seeing is files that are interpreted as text/plain and application/*compressed (maybe...) are uploading fine. Files that would be straight-up binary and interpreted as such fail. A weird work around seems to be taking the binary file and changing the extension to *.zip, which then works. For example, this file fails, but the same file, with *.zip, works.

lawinslow avatar Apr 11 '15 23:04 lawinslow

upvoting - this would be nice to have if it can be made to work.

aappling-usgs avatar Jul 17 '15 16:07 aappling-usgs

:+1:

jordansread avatar Jul 17 '15 16:07 jordansread

With the current version on master, this works for me:

cat('{"foo": 8}',file = "stuff1.json")
cat('{"bar": 9}',file = "stuff2.json")
item_upload_create(user_id(), files = c("stuff1.json", "stuff2.json"))
#> [1] "55f0bfa0e4b0dacf699ead7b"

result in GUI

screen shot 2015-09-09 at 4 24 50 pm

But doesn't work if files are in a list(), but that could be fixed easily i imagine within the helper fxn multi_file_body

sckott avatar Sep 09 '15 23:09 sckott

This problem specifically seems to manifest if you're trying to upload non-text or hard to recognize binary files. JSON works fine, but try this on for size.

f2 = system.file('extdata/This_kills_sb_upload.sbn', package='sbtools')
f1 = system.file('extdata/This_works_new_extension.zip', package='sbtools')
item_upload_create(user_id(), files = c(f1, f2))

lawinslow avatar Sep 10 '15 15:09 lawinslow