2

I'm trying to write a python script that will upload a file and changing its mime-type

from poster.encode import multipart_encode, MultipartParam
from poster.streaminghttp import register_openers
import urllib2
register_openers()
params = [MultipartParam('img', open("data.mp4", "rb").read(), filetype='image/jpeg')]
datagen, headers = multipart_encode(params)
request = urllib2.Request("http://localhost:8082/uploader.php", datagen, headers)
print urllib2.urlopen(request).read()

The uploader is dumping the $_POST and $_FILES in the document. The video that I'm uploading is going in the $_POST and not in $_FILES

I'm having a hard time to know how to make it work

EDIT:

The php code just dumps the files and posts:

var_dump($_POST);
var_dump($_FILES);

However as mentioned above, the file appears in the dump of the $_POST not the $_FILES

This is what PHP is returning:

FILES:
array(0) {
}
POST:
array(1) {
  ["img"]=>
  string(82038) "-- Content of video was here, removed because it's too long --"
}
george
  • 565
  • 1
  • 5
  • 16
  • Could you show the relevant snippet of the PHP code as well? I think it would make the problem clearer – David Robinson Apr 19 '13 at 15:43
  • the php end is: var_dump($_POST); var_dump($_FILES); – george Apr 19 '13 at 15:44
  • Would it be possible to show the output of PHP when uploading a small file? – David Robinson Apr 19 '13 at 15:47
  • Edited the question and included PHP's return – george Apr 19 '13 at 15:55
  • @DavidRobinson I think I made myself clear in the code that I removed the binary of the video, unless you want me to post 82,038 bytes in the question. Anyways, the problem is that python is sending the file in POST not FILES originally, so the problem is not with the PHP script but rather python. Anyways I managed to fix it and the problem was indeed in the python script – george Apr 28 '13 at 18:28

0 Answers0