7

I want to access a file in my computer from a google app engine application. If I put the file in the src folder of the application there is no problem but I need this file to be out of that folder.

When I try to access this file I get the next error:

Traceback (most recent call last):
File "C:\Program Files     (x86)\Google\google_appengine\google\appengine\ext\webapp\_webapp25.py", line 712, in __call__
handler.post(*groups)
File "C:\Users\path\Documents\path\oauth2client\appengine.py", line 469, in check_oauth
return method(request_handler, *args, **kwargs)
File "C:\Users\path\Documents\path\myapp.py", line 88, in post
filename=open('C:/Users/path_to_file/Documento 1.docx','r')
File "C:\Program Files (x86)\Google\google_appengine\google\appengine\tools\dev_appserver_import_hook.py", line 635, in __init__
raise IOError(errno.EACCES, 'file not accessible', filename)
IOError: [Errno 13] file not accessible: 'C:/Users/path_to_file/Documento 1.docx'

I have read that if a file is defined as static in app.yaml can't be accessible from GAE. This is my app.yaml. I can't figure out if there is something wrong:

application: myapp
version: 1
runtime: python
api_version: 1

handlers:
- url: /.*
script: myapp.py

And this is the part of the application that tries to access the file:

filename='C:/Users/path_to_file/Documento 1.docx'
media_body = MediaFileUpload(filename,resumable=True)

Does someone know why do I get the "file not accessible" error?

Thanks!

user1930068
  • 342
  • 3
  • 11
  • possible duplicate of [IOError: \[Errno 13\] file not accessible with Google AppEngine 1.6.1](http://stackoverflow.com/questions/8799304/ioerror-errno-13-file-not-accessible-with-google-appengine-1-6-1) – bain Oct 29 '14 at 10:36

2 Answers2

10

Put the file in the same directory as the rest of your applications files (i.e. where the app.yaml is).

All the files you want your application to access have to be in the same place, under your main application directory.

GAE can't access arbitrary files somewhere on your computer, just like it cannot access files saved "somewhere" else when deployed.

filename='myfile.doc'

That's assuming it's in the 'root' (same as app.yaml).

Paul Collingwood
  • 9,053
  • 3
  • 23
  • 36
  • 1
    Even if it could access such files, hardcoding their location on your harddrive in an application meant to be running on Google's cloud be be a Bad Idea. If Google can directly access your hard drive, they're not going to tell you about it. – Wooble Jan 02 '13 at 12:20
0

In your app.yaml file you need to make the file visible to your app:

 handlers:
 - url: /<location to your data files>
   script: <your app name>.app

For example in my app.yaml file it looks like this

- url: /data
  script: main.app
nanomosfet
  • 132
  • 11