error trying to upload dynamically drawn image from Flex to Rails 3 with multi-part form content -


i'm trying write little flex app has paint/canvas type feature draw image, want post rails server side. i'm following post here, can't far did due following error:

nomethoderror (undefined method `rewind' #):

i googled , found this says problem due empty filename, thought had example. however, altered example simplify post reducing form parameters, have messed since don't know i'm doing multipart form content.

i hoping @ least log request params, unfortunately can't, since it's failing before being routed , due inexperience rails. i'll ask in separate question , able edit question request params.

here's code:

public static function sendpic(simplepaint : simplepaint) : void {         var jpgsource:bitmapdata = new bitmapdata (simplepaint.width, simplepaint.height);         jpgsource.draw(simplepaint);          var jpgencoder:jpegencoder = new jpegencoder(85);         var ba:bytearray = jpgencoder.encode(jpgsource);          var request:urlrequest = new urlrequest("../drawings");         request.method = urlrequestmethod.post;         var boundary : string = "----------ij5gi3gi3ei4gi3ei4km7gi3km7km7";         request.contenttype = "multipart/form-data; boundary=" + boundary;         request.data = getmultipartrequestdata(boundary, 'drawing', 'mypic.jpg', ba);           var urlloader:urlloader = new urlloader();         urlloader.dataformat = urlloaderdataformat.binary;         urlloader.load(request);     }      private static function getmultipartrequestdata(boundary:string,                                              resourcename:string,                                              filename:string,                                              bytes:bytearray):bytearray {         //alert.show("haha");         var lf:string = "\r\n";          var part1:string = '--' + boundary + lf +              'content-disposition: form-data; name="filename"' + lf + lf +             '{0}' + lf +              '--' + boundary + lf ;         part1 += 'content-disposition: form-data; name="commit"' + lf + lf +                    'create' + lf +                   '--' + boundary + lf +                                        'content-disposition: form-data; name="{1}[pic] ";' +                    'filename="{0}"' + lf +                                           'content-type: application/octet-stream' + lf + lf               var part2:string = '--' + boundary + lf +                             'content-disposition: form-data; name="upload"' + lf + lf +                            'submit query' + lf +                            '--' + boundary + '--'          var result:bytearray = new bytearray();         // filling in parameters per comment above         result.writemultibyte(stringutil.substitute(part1,                                                      filename,                                                     resourcename), "ascii");         result.writebytes(bytes,0,bytes.length);         result.writemultibyte(part2, "ascii");         return result;     } 

the answer in answer of earlier linked question. had missed it, or undid it, in copy-paste-edit of answer.

the code needs change part :

'content-disposition: form-data; name="{1}[pic] ";' +                    'filename="{0}"' + lf +                                           'content-type: application/octet-stream' + lf + lf  

it needs changed to:

'content-disposition: form-data; name="{1}[pic]"; ' +  // space moved here                  'filename="{0}"' + lf +                                           'content-type: application/octet-stream' + lf + lf    

when move space after semicolon, works.


Comments

Popular posts from this blog

c# - SharpSVN - How to get the previous revision? -

c++ - Is it possible to compile a VST on linux? -

url - Querystring manipulation of email Address in PHP -