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 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.