0

https://github.com/sergiomb2/MultipartPostHandler2

MultipartPostHandler needs to identify type of variables as file, I got a string with an image
Now I do :

outfile = open(tmpfile,'w')
outfile.write(img)
outfile.close()

params = { 'img': open(tmpfile, "rb"), ...

but seems to me a workaround, have to write file in File System , I'd like to know how I create a file descriptor with a buffer with content of img variable . I tried StringIO but stringIO isn't of type file

for(key, value) in params.items():
    if type(value) == file:
        v_files.append((key, value))

give me cStringIO.StringI and don't have fileno

for(key, fd) in files:
    file_size = os.fstat(fd.fileno())[stat.ST_SIZE]
    filename = fd.name.split('/')[-1]

doesn't work

Lafexlos
  • 7,618
  • 5
  • 38
  • 53
Sérgio
  • 6,966
  • 1
  • 48
  • 53
  • 1
    http://stackoverflow.com/a/19079887/110707 tells you how to get the size without having a fileno. – Wooble May 12 '14 at 18:25
  • It is a bit unclear to me what you are up to. If you need to get the file size, please refer to what @Wooble has linked. If you have a different problem, please edit your question. – Jonas Schäfer May 12 '14 at 18:32
  • no I need get: type(var) == file – Sérgio May 12 '14 at 19:24
  • 1
    where is `f` coming from? obviously, you/someone is setting `f` to a `StringIO` object. find that and you'll have your answer. – acushner May 12 '14 at 19:34

0 Answers0