0
votes

I have a (ndb.model) 'table' in app engine to which I need to add 'attachments' such as .jpg, .doc, xls and so on. I cannot pre-determine what these files will be, it's up to the user. This was reasonably easy using blobkey / blobstore but I am having trouble with Google Cloud Storage for this purpose.

my html is simple:

<label for="form_attach">Please select Attachment</label>
<input type="file" name="form_attach" id="form_attach" />

My Python code is also simple:

tempblob = self.request.get('form_attach')
logging.error(repr(tempblob))  -- shows the contents of tempblob

So... How do I know the content-type (mime type) of the incoming blob so that I can save it in Google Cloud Storage correctly? I need to set the content-type when the blob is stored so that it will serve / display correctly.

gcs.stat(...).content_type looks like it's what I need but it requires a valid, stored, GCS file from which to retrieve the information. Similarly Python's mimetypes needs a file name but I seem to retrieve the contents of the file.

Any pointers will be appreciated.

Thanks David

1
You might find this helpful: blog.whiteoctober.co.uk/2016/08/01/… - gaefan
Thanks Jeff, much appreciated - David Freeman

1 Answers

0
votes

Jeff O'Neill's link provided the answers I was looking for, thanks. Question will be closed.