HTTP Post Upload Multiple Files from iOS to PHP -


in ios app, i'm building nsdata use body nsmutableurlrequest can upload multiple files in 1 http post.

the contents of post body (with file data removed , replaced byte count):

multipart/form-data; charset=utf-8; boundary=0xkhtmlboundary --0xkhtmlboundary content-disposition: form-data; name="email" myemailaddress@gmail.com --0xkhtmlboundary content-disposition: form-data; name="sqlite"; filename="backup.myapp.v1.1.3-to-v1.1.3.1443578420.sqlite" content-type: application/octet-stream  // ... data length: 880640  --0xkhtmlboundary-- content-disposition: form-data; name="sqliteshm"; filename="backup.myapp.v1.1.3-to-v1.1.3.1443578420.sqlite-shm" content-type: application/octet-stream  // ... data length: 32768  --0xkhtmlboundary-- content-disposition: form-data; name="sqlitewal"; filename="backup.myapp.v1.1.3-to-v1.1.3.1443578420.sqlite-wal" content-type: application/octet-stream  // ... data length: 3901672  --0xkhtmlboundary-- 

however, on php side when receive post, i'm seeing first of 3 files. if put 1 named "sqlite" first, on php side, see "sqlite" file. if put 1 named "sqliteshm" first, see "sqliteshm" file in $_files array.

array ( 'sqliteshm' =>      array (       'name' => 'backup.myapp.v1.1.3-to-v1.1.3.1443578420.sqlite-shm',       'type' => 'application/octet-stream',       'tmp_name' => '/private/var/tmp/phpk1wywb',       'error' => 0,       'size' => 32768,     ), ) 

the file size matches up, regardless of 1 put first, first file ever shows on php side.

do need special in order receive multiple files on php side?

or sending multiple files incorrect ios?

in short, request not valid.

in more detail, notice difference between --0xkhtmlboundary-- , --0xkhtmlboundary. separator uses 2 dashes @ end -- terminator. result, request body isn't parsed beyond first terminator, happens right after first file. there should 1 terminator - @ end of request.

generally, shouldn't reinvent wheel when comes composing multipart form data requests. use proven , time tested library afnetworking.


Comments

Popular posts from this blog

html - Outlook 2010 Anchor (url/address/link) -

javascript - Why does running this loop 9 times take 100x longer than running it 8 times? -

Getting gateway time-out Rails app with Nginx + Puma running on Digital Ocean -