向Google Storage抛出API CallNotFoundExcpetion写入图片

时间:2019-04-12 15:47:17

标签: java google-app-engine google-cloud-platform google-cloud-storage google-cloud-sdk

我正在尝试将图像存储在Google Storage中,并通过他们的一个论坛找到了一些测试代码。

我已经添加了各种依赖关系,并希望逐步遍历代码,但是在走得很远之前,我遇到了这个异常。我应该补充一点,这是本地测试,没有使用appEngine,而且我已经在网上寻找各种资源,但是很茫然。

我找到的代码是(我已经修改了存储段名称和文件的网址):

    public static void test() throws IOException {
        GcsService gcsService = GcsServiceFactory.createGcsService();
        BlobstoreService blobstoreService = BlobstoreServiceFactory.getBlobstoreService();

        GcsFileOptions options = new GcsFileOptions.Builder()
                .mimeType(".jpg")
                .acl("project-private")
                .build();

        String bucketName = "my_test_bucket";
        String secureFilename = "https://helpx.adobe.com/uk/stock/how-to/visual-reverse-image-search/_jcr_content/main-pars/image.img.jpg/visual-reverse-image-search-v2_1000x560.jpg";

        GcsFilename p_filename = new GcsFilename(bucketName, secureFilename);
        GcsOutputChannel writeChannel = gcsService.createOrReplace(p_filename, options); //exception here
        //writeChannel.write(ByteBuffer.wrap(image.getImageData()));
        writeChannel.close();

        BlobKey blobKey = blobstoreService.createGsBlobKey("/gs/" + p_filename.getBucketName() + "/" + p_filename.getObjectName());

        ImagesService imageService = ImagesServiceFactory.getImagesService();
        ServingUrlOptions servoptions = ServingUrlOptions.Builder.withBlobKey(blobKey).secureUrl(true);
        String url = imageService.getServingUrl(servoptions);
    }

调用createOrReplace时会发生异常。

例外是:

        Apr 12, 2019 4:37:48 PM com.google.appengine.tools.cloudstorage.RetryHelper doRetry
    WARNING: RetryHelper(432.2 ms, 1 attempts, com.google.appengine.tools.cloudstorage.GcsServiceImpl$1@12331b): Attempt 1 failed, sleeping for 85 ms: com.google.apphosting.api.ApiProxy$CallNotFoundException: Can't make API call file.Create in a thread that is neither the original request thread nor a thread created by ThreadManager
    Apr 12, 2019 4:37:48 PM com.google.appengine.tools.cloudstorage.RetryHelper doRetry
    WARNING: RetryHelper(621.2 ms, 2 attempts, com.google.appengine.tools.cloudstorage.GcsServiceImpl$1@12331b): Attempt 2 failed, sleeping for 128 ms: com.google.apphosting.api.ApiProxy$CallNotFoundException: Can't make API call file.Create in a thread that is neither the original request thread nor a thread created by ThreadManager
    Apr 12, 2019 4:37:48 PM com.google.appengine.tools.cloudstorage.RetryHelper doRetry
    WARNING: RetryHelper(761.3 ms, 3 attempts, com.google.appengine.tools.cloudstorage.GcsServiceImpl$1@12331b): Attempt 3 failed, sleeping for 253 ms: com.google.apphosting.api.ApiProxy$CallNotFoundException: Can't make API call file.Create in a thread that is neither the original request thread nor a thread created by ThreadManager
    Apr 12, 2019 4:37:48 PM com.google.appengine.tools.cloudstorage.RetryHelper doRetry
    WARNING: RetryHelper(1.026 s, 4 attempts, com.google.appengine.tools.cloudstorage.GcsServiceImpl$1@12331b): Attempt 4 failed, sleeping for 495 ms: com.google.apphosting.api.ApiProxy$CallNotFoundException: Can't make API call file.Create in a thread that is neither the original request thread nor a thread created by ThreadManager
    Apr 12, 2019 4:37:49 PM com.google.appengine.tools.cloudstorage.RetryHelper doRetry
    WARNING: RetryHelper(1.533 s, 5 attempts, com.google.appengine.tools.cloudstorage.GcsServiceImpl$1@12331b): Attempt 5 failed, sleeping for 1278 ms: com.google.apphosting.api.ApiProxy$CallNotFoundException: Can't make API call file.Create in a thread that is neither the original request thread nor a thread created by ThreadManager
    Apr 12, 2019 4:37:50 PM com.google.appengine.tools.cloudstorage.RetryHelper doRetry
    WARNING: RetryHelper(2.824 s, 6 attempts, com.google.appengine.tools.cloudstorage.GcsServiceImpl$1@12331b): Attempt 6 failed, sleeping for 2984 ms: com.google.apphosting.api.ApiProxy$CallNotFoundException: Can't make API call file.Create in a thread that is neither the original request thread nor a thread created by ThreadManager
    Disconnected from the target VM, address: '127.0.0.1:57754', transport: 'socket'
    com.google.appengine.tools.cloudstorage.RetriesExhaustedException: RetryHelper(2.832 s, 6 attempts, com.google.appengine.tools.cloudstorage.GcsServiceImpl$1@12331b): Too many failures, giving up
        at com.google.appengine.tools.cloudstorage.RetryHelper.doRetry(RetryHelper.java:100)
        at com.google.appengine.tools.cloudstorage.RetryHelper.runWithRetries(RetryHelper.java:123)
        at com.google.appengine.tools.cloudstorage.GcsServiceImpl.createOrReplace(GcsServiceImpl.java:32)
        at gametest.Application.test(Application.java:55)
        at gametest.Application.main(Application.java:69)
    Caused by: com.google.apphosting.api.ApiProxy$CallNotFoundException: Can't make API call file.Create in a thread that is neither the original request thread nor a thread created by ThreadManager
        at com.google.apphosting.api.ApiProxy$CallNotFoundException.foreignThread(ApiProxy.java:800)
        at com.google.apphosting.api.ApiProxy.makeSyncCall(ApiProxy.java:112)
        at com.google.apphosting.api.ApiProxy.makeSyncCall(ApiProxy.java:65)
        at com.google.appengine.api.files.FileServiceImpl.makeSyncCall(FileServiceImpl.java:591)
        at com.google.appengine.api.files.FileServiceImpl.create(FileServiceImpl.java:512)
        at com.google.appengine.api.files.FileServiceImpl.createNewGSFile(FileServiceImpl.java:157)
        at com.google.appengine.tools.cloudstorage.dev.LocalRawGcsService.beginObjectCreation(LocalRawGcsService.java:106)
        at com.google.appengine.tools.cloudstorage.dev.LocalRawGcsService.beginObjectCreation(LocalRawGcsService.java:44)
        at com.google.appengine.tools.cloudstorage.GcsServiceImpl$1.run(GcsServiceImpl.java:35)
        at com.google.appengine.tools.cloudstorage.GcsServiceImpl$1.run(GcsServiceImpl.java:32)
        at com.google.appengine.tools.cloudstorage.RetryHelper.doRetry(RetryHelper.java:78)
        ... 4 more

    Process finished with exit code 0

任何帮助解决的方法都将非常棒,谢谢您。

0 个答案:

没有答案