upload and extract zip file with curl

3,478 views
Skip to first unread message

Kate Alpert

unread,
Oct 21, 2014, 4:05:51 PM10/21/14
to Xnat
Hi folks,

I was wondering how to upload and extract a zip file using curl.  With XnatDataClient, I use -l for the local file, but I can't figure out the proper flag with curl.  I've tried -d @filename.zip and -T filename.zip, but no luck.  Anyone know offhand?

Thanks,
Kate

Chris Fahim

unread,
Nov 12, 2014, 1:34:55 PM11/12/14
to xnat_di...@googlegroups.com

There a dozen ways to do it with cURL.  The -d should work, but I prefer using cURL like I'm filling out a form for easy reading, i.e. -F. 

You can add more parameters if you need to specify subject, experiment labels, etc..  I found it easiest to have this built into the zip folder structure. 

Here is how I've done it using v1.6.3 of XNAT



curl.exe -F "dest=/prearchive/projects/T01" -F "FILE=@C:\yourfilepath.zip" -u USERNAME:PASSWORD http://yourxnaturl



Kate Alpert

unread,
Dec 4, 2014, 12:19:11 PM12/4/14
to Xnat
The -F didn't work for me, however, I've made some progress.  The following command uploads the zip file, however, it doesn't extract the contents (instead, I get a file called "upload.unsupported", which is the zip file):

curl -u $uname:$pass -X PUT "$host/data/experiments/$id/assessors/FS_v5-3-0_$id/out/resources/DATA/files?extract=true&overwrite=true&inbody=true" -T test.zip


Any idea how I can achieve the extraction?

Thanks,
Kate


Flavin, John

unread,
Dec 4, 2014, 12:21:45 PM12/4/14
to xnat_di...@googlegroups.com
Try removing the “/out"

--
You received this message because you are subscribed to the Google Groups "xnat_discussion" group.
To unsubscribe from this group and stop receiving emails from it, send an email to xnat_discussi...@googlegroups.com.
To post to this group, send email to xnat_di...@googlegroups.com.
Visit this group at http://groups.google.com/group/xnat_discussion.
For more options, visit https://groups.google.com/d/optout.




The material in this message is private and may contain Protected Healthcare Information (PHI). If you are not the intended recipient, be advised that any unauthorized use, disclosure, copying or the taking of any action in reliance on the contents of this information is strictly prohibited. If you have received this email in error, please immediately notify the sender via telephone or return mail.

Kate Alpert

unread,
Dec 4, 2014, 12:23:30 PM12/4/14
to Xnat
Removing the "/out" didn't make a difference.

Tim Olsen

unread,
Dec 4, 2014, 12:27:46 PM12/4/14
to xnat_di...@googlegroups.com

Try adding a file name to the url with a .zip extension.  I’m not sure what the http message curl builds there looks like.  But upload.unsupported tends to show up when XNAT can’t figure out the name of a file.  So, just give it one.  It will be ignored after the file is extracted.

 

curl -u $uname:$pass -X PUT "$host/data/experiments/$id/assessors/FS_v5-3-0_$id/out/resources/DATA/files/test.zip?extract=true&overwrite=true&inbody=true" -T test.zip

 

Tim

No virus found in this message.
Checked by AVG - www.avg.com
Version: 2015.0.5577 / Virus Database: 4235/8668 - Release Date: 12/02/14

Kate Alpert

unread,
Dec 4, 2014, 12:32:18 PM12/4/14
to Xnat
Success! Thanks, Tim!!
Reply all
Reply to author
Forward
0 new messages