Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/google-app-engine/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在GAE blobstore java中创建文件_Java_Google App Engine - Fatal编程技术网

在GAE blobstore java中创建文件

在GAE blobstore java中创建文件,java,google-app-engine,Java,Google App Engine,在我的应用程序中,我有一个字符串,它是一个文件内容。我需要在blobstore中创建包含此内容的新文件。我试着像这样使用文件API: FileService fileService = FileServiceFactory.getFileService(); AppEngineFile file = fileService.createNewBlobFile("text/plain"); FileWriteChannel writeChannel = fileServic

在我的应用程序中,我有一个字符串,它是一个文件内容。我需要在blobstore中创建包含此内容的新文件。我试着像这样使用文件API:

    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已弃用,我只收到以下错误:

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中手动创建文件,因为用户只将数据内容作为字符串提供给我,而不是文件本身,所以我不能使用您应该写入的
。
文件API是,并且Blobstore API是正确的
不提供直接写入的编程方式

稍后,您可以使用谷歌云存储自己的API或 您还可以使用BlobStoreAPI通过BlobKey为其执行此操作

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());
}