0
votes

im trying to upload an excel that is obtained from a url using google app engine urlfetch. I can access all its headers. I now need to upload the same into the blobstore. The following is the code i wrote

class Send_Handler(webapp2.RequestHandler):
    def get(self):
        url = "http://abc.xls"
        result = None
        fetch_(url, result, 'GET') 
        #     self.response.out.write(result.content)

def fetch_(url, result, method):
    # logging.info(result)
    if method=='GET':
        result = urlfetch.fetch(url)
        if result.status_code == 200:
            upload_url = blobstore.create_upload_url('/attachupload')
            logging.info(upload_url)
            fetch_(upload_url, result, 'POST')
    else:
        try:
            r_headers = result.headers
            logging.info(result.content)
            result_2 = urlfetch.fetch(url=url, payload=result.content,method=urlfetch.POST, headers=r_headers)
            # logging.info(result_2)
        except Exception, e:
            logging.error(e)

when run, it returns an error "TypeError: not indexable"

The following are the headers i got

alternate-protocol: 80:quic,80:quic server: Google Frontend transfer-encoding: chunked date: Mon, 21 Jul 2014 13:18:16 GMT content-type: application/msexcel cache-control: no-cache content-transfer-encoding: Binary content-disposition: attachment; filename="abc.xls"

this excel file url is obtained from another webapp

1
Where is the code for fetch_thing?loki
Check the answer below since you need to encode your post as it were an html form in order to upload to the blob.loki

1 Answers

2
votes

I wrote this Gist a couple of months ago, about uploading a blob to the blobstore using an upload_url and urlfetch. The example code reads an existing blob from the blobstore.

To send a blob to the blobstore you have to send a mulitipart/form-data.