According to the official documentation [1] you have to: a. Create the application specific upload URL. b. Use this URL as the action for the form you use to accept uploads.
Please check this thread for a similar use case [2]. ------------------------------- [1]. https://cloud.google.com/appengine/docs/standard/php/googlestorage/user_upload [2]. https://groups.google.com/forum/#!topic/google-appengine/-dDyLY3owCU On Monday, July 20, 2020 at 9:00:59 PM UTC+2, 전하정 wrote: > > Hi. I am trying to make a website that allows users to upload their own > files, and I figured that it would be nice to store the files to the GCS. > > Therefore, I am trying to make an API that can upload a file from a local > computer(paths like C:/user/..) to my GCS bucket. > > The problem is that when I run the project locally(at localhost:8080), the > API works well and uploads the file to my bucket. > > However, when I deploy the project to Google App Engine and run it(at > {my-project-id}.appspot.com, it returns java.nio.file.NoSuchFileException > and fails to upload the file. > > I've been stuck with this problem for almost a week, and I am wondering if > it is not allowed for GAE to get access to user's file system. > > Here is the code that I used to upload the project, which is the same as > the code from google doc > <https://cloud.google.com/storage/docs/uploading-objects#storage-upload-object-code-sample> > about > this topic. > > Storage storage = > StorageOptions.newBuilder().setProjectId(projectId).build().getService(); > BlobId blobId = BlobId.of(uploadReqDto.getBucketName(), > uploadReqDto.getUploadFileName()); > BlobInfo blobInfo = BlobInfo.newBuilder(blobId).build(); > storage.create(blobInfo, > Files.readAllBytes(Paths.get(uploadReqDto.getLocalFileLocation()))); > > uploadReqDto.getUploadFileName() and uploadReqDto.getLocalFileLocation() > are the parameter of my POST API, which looks like > > { > "uploadFileName": "sooktubeTest1.txt", > "localFileLocation": "C:/users/my/file/path" > } > > I am almost sure that there is a problem with my localFileLocation > variable, but I don't know how to fix it. It seems like GAE cannot get any > file path. > Is there any special way to upload user's local file to GCS when the > project is deployed on GAE? > > thanks. > -- You received this message because you are subscribed to the Google Groups "Google App Engine" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/google-appengine/7227b063-cc26-41aa-852c-a3e18fd488aao%40googlegroups.com.
