English 中文(简体)
使用远程 Api 的 appengine 文件服务
原标题:appengine fileservice using remote api

I am trying to programmatically upload some files to the blobstore and also update something in the datastore. It could be done using a specialized servlet and CURL to do it, but it would be more elegant to use the remote api. Is it possible to use the file service thru appengine s remote apis? If yes, why am I getting this exception when executing bos.write(b)? Thanks code:

String localFileName = "c:\actcut fail.jpg";
                AppEngineFile aeF = fileService.createNewBlobFile("", "actcutfail.jpg");
                FileWriteChannel writeChannel = (FileWriteChannel) fileService.openWriteChannel(aeF, true); 
                BufferedOutputStream bos = new BufferedOutputStream(Channels.newOutputStream(writeChannel));
                FileInputStream fis = new FileInputStream(localFileName);
                try {
                    while (true) {
                        int b = fis.read();
                        bos.write(b);
                    }
                } catch (EOFException eofex) {
                    // end of file reached
                } catch (Exception ex) {
                    ex.printStackTrace();
                } finally {
                    fis.close();
                    bos.flush();
                    bos.close();
                    writeChannel.closeFinally();
                    System.out.println("uploaded blob file with key=" + fileService.getBlobKey(aeF).getKeyString());
                }

例外:

java.io.IOException
    at com.google.appengine.api.files.FileServiceImpl.translateException(FileServiceImpl.java:601)
    at com.google.appengine.api.files.FileServiceImpl.makeSyncCall(FileServiceImpl.java:574)
    at com.google.appengine.api.files.FileServiceImpl.append(FileServiceImpl.java:510)
    at com.google.appengine.api.files.FileServiceImpl.append(FileServiceImpl.java:255)
    at com.google.appengine.api.files.FileWriteChannelImpl.write(FileWriteChannelImpl.java:52)
    at com.google.appengine.api.files.FileWriteChannelImpl.write(FileWriteChannelImpl.java:44)
    at java.nio.channels.Channels.write(Channels.java:63)
    at java.nio.channels.Channels.access$000(Channels.java:47)
    at java.nio.channels.Channels$1.write(Channels.java:134)
    at java.io.BufferedOutputStream.flushBuffer(BufferedOutputStream.java:65)
    at java.io.BufferedOutputStream.write(BufferedOutputStream.java:78)
    at cri.uploaddevalle.UploadDevalle.main(UploadDevalle.java:61)
Caused by: com.google.apphosting.api.ApiProxy$ApplicationException: ApplicationError: 10: File not opened: /blobstore/writable:GlPgcwTQdPtgYVY_Jpk9hg
    at com.google.appengine.api.files.dev.LocalFileService.throwError(LocalFileService.java:206)
    at com.google.appengine.api.files.dev.LocalFileService.append(LocalFileService.java:352)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at com.google.appengine.tools.development.ApiProxyLocalImpl$AsyncApiCall.callInternal(ApiProxyLocalImpl.java:498)
    at com.google.appengine.tools.development.ApiProxyLocalImpl$AsyncApiCall.call(ApiProxyLocalImpl.java:452)
    at com.google.appengine.tools.development.ApiProxyLocalImpl$AsyncApiCall.call(ApiProxyLocalImpl.java:430)
    at java.util.concurrent.Executors$PrivilegedCallable$1.run(Executors.java:463)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.util.concurrent.Executors$PrivilegedCallable.call(Executors.java:460)
    at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303)
    at java.util.concurrent.FutureTask.run(FutureTask.java:138)
    at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
    at java.lang.Thread.run(Thread.java:619)
java.io.IOException
    at com.google.appengine.api.files.FileServiceImpl.translateException(FileServiceImpl.java:601)
    at com.google.appengine.api.files.FileServiceImpl.makeSyncCall(FileServiceImpl.java:574)
    at com.google.appengine.api.files.FileServiceImpl.append(FileServiceImpl.java:510)
    at com.google.appengine.api.files.FileServiceImpl.append(FileServiceImpl.java:255)
    at com.google.appengine.api.files.FileWriteChannelImpl.write(FileWriteChannelImpl.java:52)
    at com.google.appengine.api.files.FileWriteChannelImpl.write(FileWriteChannelImpl.java:44)
    at java.nio.channels.Channels.write(Channels.java:63)
    at java.nio.channels.Channels.access$000(Channels.java:47)
    at java.nio.channels.Channels$1.write(Channels.java:134)
    at java.io.BufferedOutputStream.flushBuffer(BufferedOutputStream.java:65)
    at java.io.BufferedOutputStream.flush(BufferedOutputStream.java:123)
    at cri.uploaddevalle.UploadDevalle.main(UploadDevalle.java:69)
Caused by: com.google.apphosting.api.ApiProxy$ApplicationException: ApplicationError: 10: File not opened: /blobstore/writable:GlPgcwTQdPtgYVY_Jpk9hg
    at com.google.appengine.api.files.dev.LocalFileService.throwError(LocalFileService.java:206)
    at com.google.appengine.api.files.dev.LocalFileService.append(LocalFileService.java:352)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at com.google.appengine.tools.development.ApiProxyLocalImpl$AsyncApiCall.callInternal(ApiProxyLocalImpl.java:498)
    at com.google.appengine.tools.development.ApiProxyLocalImpl$AsyncApiCall.call(ApiProxyLocalImpl.java:452)
    at com.google.appengine.tools.development.ApiProxyLocalImpl$AsyncApiCall.call(ApiProxyLocalImpl.java:430)
    at java.util.concurrent.Executors$PrivilegedCallable$1.run(Executors.java:463)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.util.concurrent.Executors$PrivilegedCallable.call(Executors.java:460)
    at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303)
    at java.util.concurrent.FutureTask.run(FutureTask.java:138)
    at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
    at java.lang.Thread.run(Thread.java:619)
最佳回答

文件 API 目前不完全支持远程 _ api 。 您应该能够同时获得文件上传 URL, 但是如果您想要实际上传文件, 您需要将文件寄到自定义服务器 。

问题回答

暂无回答




相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...

热门标签