I am unable to figure out what I am doing wrong while uploading file using web form (python, webapp2, gae) and writing to cloud storage (GCS)
jinja2 template
<form action="/upload_data" method="post">
<input type="file" name="add_scanned_data_file" enctype="multipart/form-data">
<input type="image" src="stylesheets/add_data.png" alt="submit" align="left"></form>
webapp2 code
fx = self.request.body_file
fx_name = "some_name"
gcs_file = gcs.open(_GCS_BUCKET_NAME + fx_name, 'w')
gcs_file.write(fx.read())
gcs_file.close()
The file gets uploaded to GCS but incorrectly. The content of uploaded file in GCS shows only the file name with some form parameter string. So it appears that I am not reading input file from webform properly.
_________Edit (Text added below)___________
While this (adding multipart in form tag) works so far and (gcs_file.write(fx.read()) uploads file in GCS. However when I try to read that file (either from GCS Browser or by self.response.write(gcs_file.read()) ), I get output as below (which means I need to do something with file metadata??)
------WebKitFormBoundaryk9MfD0ETQjUVirBO Content-Disposition: form-data; name="add_scanned_data_update_date" ------WebKitFormBoundaryk9MfD0ETQjUVirBO Content-Disposition: form-data; name="add_scanned_data_text" Upload ------WebKitFormBoundaryk9MfD0ETQjUVirBO Content-Disposition: form-data; name="add_scanned_data_file"; filename="sample.jpg" Content-type: image/jpeg ����JFIF,,��xPhotoshop 3.08BIM\gP53616c7465645f5f605b5cccc1a3ffb06bd320d5ad9ccaa25a68c613f04d7ad0dcaed6e1c049c109��C��C