Mezeo Ready Developer Center
February 09, 2012, 03:22:52 PM *
Welcome, Guest. Please login or register.

Login with username, password and session length
News:
 
   Home   Help Search Login Register  
Pages: [1]
Author Topic: [EXAMPLE] Uploading multiple parts to a single file via separate curl commands  (Read 251 times)
gtillman
Mezeo Employee
Newbie
*****
Posts: 3


View Profile
« on: June 30, 2010, 04:23:32 PM »

The example that follows uses these files:


Code:
$ ls -l
-rw-r--r-- 1 gordy gordy 108 2010-06-30 15:48 file.xml
-rw-r--r-- 1 gordy gordy  17 2010-06-30 15:39 part1.dat
-rw-r--r-- 1 gordy gordy  17 2010-06-30 15:39 part2.dat

file.xml:

Code:
<file>
    <name>sample.txt</name>
    <mime_type>text/plain</mime_type>
    <public>false</public>
</file>

part1.dat:

Code:
This is part 1.


part2.dat:

Code:
This is part 2.



First I'll create a file by posting it to my root container's contents URI.

Code:
$ curl -i -u ACCOUNT:PASSWORD \
-X POST \
-H 'X-Client-Specification: 2' \
-H 'Content-Type: application/vnd.csp.file-info+xml' \
https://pcsbeta.mezeo.net/v2/containers/682FC496-40C8-11DF-8C48-BF2FA59144D5/contents \
-d@file.xml

HTTP/1.1 201 Created
Date: Wed, 30 Jun 2010 20:48:57 GMT
Server: Apache/2.2.3 (Red Hat)
Location: https://pcsbeta.mezeo.net/v2/files/E77E5D80-8488-11DF-A5E9-0030485F2412
Transfer-Encoding: chunked
Content-Type: text/uri-list

https://pcsbeta.mezeo.net/v2/files/E77E5D80-8488-11DF-A5E9-0030485F2412

Notice the URI of the new file that was created?  Now I will upload my first
part by PUTting it to the content URI of the file I just created.  I know that
I am uploading a total of 34 bytes and am going to write the first 17 bytes.

Code:
$ curl -i -u ACCOUNT:PASSWORD \
-X PUT \
-H 'Content-Range: bytes 0-16/34' \
https://pcsbeta.mezeo.net/v2/files/E77E5D80-8488-11DF-A5E9-0030485F2412/content \
--data-binary @part1.dat

Now I will upload the second part.  I know that I am uploading the last 17
bytes of the file.

Code:
$ curl -i -u ACCOUNT:PASSWORD \
-X PUT \
-H 'Content-Range: bytes 17-34/34' \
https://pcsbeta.mezeo.net/v2/files/E77E5D80-8488-11DF-A5E9-0030485F2412/content \
--data-binary @part2.dat


Now let's download the file and check our work:

Code:
$ curl -i -u ACCOUNT:PASSWORD \
https://pcsbeta.mezeo.net/v2/files/E77E5D80-8488-11DF-A5E9-0030485F2412/content

HTTP/1.1 200 OK
Date: Wed, 30 Jun 2010 21:12:14 GMT
Server: Apache/2.2.3 (Red Hat)
Cache-Control: no-cache
Content-Disposition: attachment; filename=sample.txt
Transfer-Encoding: chunked
Content-Type: text/plain; charset=UTF-8

This is part 1.

This is part 2.




Logged
Pages: [1]
 
Jump to:  

© Mezeo Software. All rights reserved. | Privacy Policies | Contact Us | Powered by SMF 1.1.11 | SMF © 2006-2009, Simple Machines LLC