Friday 15 January 2010

python - How to store a CSV file uploaded via Django into a blobstore on Google App Engine? -


I am trying to upload a CSV file through a Django app in a blobostore file in Google App Engine. I'm running into a problem that was dumping the uploaded file, it could end up with the wrong newlines, so, I need to open the uploaded file in Dragon's Universal Newline mode. Django document suggests that I have a file object on it. I can use Open (), setting a new mode.

Here's my proposed solution:

  filename = files.blobstore with files.open (filename, 'a') as Output_file (mime_type = 'text / Csv ') csvfile = request.FILES.get (' csvfile '). Input_file as csvfile.open (mode = 'ru'): Output_file.write (input_file.readline ())   

('file' is part of the app engine's API)

It seems right to me, but I wanted to know if anyone else has come under similar situation and a better solution?

I already manage to do this. You must iterate the uploaded file

  file name = files.blobstore.create (mime_type = 'text / csv') csvfile = request.FILES.get ('csvfile') files. Output_file (file name, 'a') with open (for example csvfile.read () csv.reader output_file: author = csv.writer (output_file, quoting = csv.QUOTE_NONE). Splitlines ()): writer .writerow (line) files.finalize (filename)   

Hope this works

No comments:

Post a Comment