mardi 29 septembre 2015

HTTP Post Upload Multiple Files from iOS to PHP

In my iOS app, I'm building an NSData to use as the body for an NSMutableURLRequest so that I can upload multiple files in one HTTP POST.

The contents of my post body look like this (with the file data removed and just replaced with the 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 the PHP side when I receive this post, I'm only seeing the first of the three files. If I put the one named "sqlite" first, then on the PHP side, I only see the "sqlite" file. If I put the one named "sqliteshm" first, then I only see the "sqliteshm" file in the $_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 which one I put first, but only the first file ever shows up on the PHP side.

Do I need to do something special in order to receive multiple files on the PHP side?

Or am I sending the multiple files incorrect from iOS?

Aucun commentaire:

Enregistrer un commentaire