В моем приложении у меня есть строка, которая является содержимым файла. Мне нужно создать новый файл с этим контентом в blobstore. Я судимый использовать File API, как это:Создание файла в GAE blobstore java
FileService fileService = FileServiceFactory.getFileService();
AppEngineFile file = fileService.createNewBlobFile("text/plain");
FileWriteChannel writeChannel = fileService.openWriteChannel(file, true);
writeChannel.write(ByteBuffer.wrap(content.getBytes()));
writeChannel.closeFinally();
BlobKey blobKey = fileService.getBlobKey(file);
res.sendRedirect("/serve?blob-key=" + blobKey);
Но поскольку API File осуждается я только получаю эту ошибку:
HTTP ERROR 500
Problem accessing /create_timetable. Reason:
The Files API is disabled. Further information: https://cloud.google.com/appengine/docs/deprecations/files_api
Caused by:
com.google.apphosting.api.ApiProxy$FeatureNotEnabledException: The Files API is disabled. Further information: https://cloud.google.com/appengine/docs/deprecations/files_api
at com.google.appengine.tools.development.ApiProxyLocalImpl$AsyncApiCall.callInternal(ApiProxyLocalImpl.java:515)
at com.google.appengine.tools.development.ApiProxyLocalImpl$AsyncApiCall.call(ApiProxyLocalImpl.java:484)
at com.google.appengine.tools.development.ApiProxyLocalImpl$AsyncApiCall.call(ApiProxyLocalImpl.java:461)
at java.util.concurrent.Executors$PrivilegedCallable$1.run(Executors.java:533)
at java.security.AccessController.doPrivileged(Native Method)
at java.util.concurrent.Executors$PrivilegedCallable.call(Executors.java:530)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)
Как можно вручную создать файл в Blobstore, поскольку пользователь только дает мне данные содержание в виде строки, а не сам файл, так что я не могу использовать <form action="blobstoreService.createUploadUrl("/upload") %>"
и <input type="file">
Update
Как сказал @ozarov, я сделал это с помощью API Google Cloude Storage API и написал функцию ниже. Он также возвращает BlobKey этого файла, чтобы вы могли получить к нему доступ с помощью API Blobstore.
private BlobKey saveFile(String gcsBucket, String fileName,
String content) throws IOException {
GcsFilename gcsFileName = new GcsFilename(gcsBucket, fileName);
GcsOutputChannel outputChannel =
gcsService.createOrReplace(gcsFileName, GcsFileOptions.getDefaultInstance());
outputChannel.write(ByteBuffer.wrap(content.getBytes()));
outputChannel.close();
return blobstoreService.createGsBlobKey(
"/gs/" + gcsFileName.getBucketName() + "/" + gcsFileName.getObjectName());
}