使用JAVA Google应用引擎(GAE)在Google云端服务上传图片

时间:2014-01-24 09:33:50

标签: java jsp google-app-engine google-cloud-datastore google-cloud-storage

我想从表单提交中上传图片。

还有其他代码吗?请建议我。

我的JSP页面代码是:

<form class="form-horizontal" role="form" id="" method="post" action="upload-image" >
      <input type="file" name="myPhoto" />
      <input type="submit" />
</form>

我的web.xml

    <servlet>
        <servlet-name>uploadImage</servlet-name>
        <servlet-class>com.test.test.uploadData</servlet-class>
    </servlet>
    <servlet-mapping>
        <servlet-name>clientAddAuth</servlet-name>
        <url-pattern>/upload-image</url-pattern>
    </servlet-mapping>

我的Servlet

String  file = req.getParameter("myPhoto");
//GcsService fileName = gcsService.createOrReplace(filename, options);
GcsFilename fileName = new GcsFilename("MyBucket", "1524661_554402494654161_482662946_n.png");

BlobstoreService blobstoreService = BlobstoreServiceFactory.getBlobstoreService();
BlobKey blobKey = blobstoreService.createGsBlobKey(
                        "/gs/" + fileName.getBucketName() + "/" + fileName.getObjectName()
                        );
blobstoreService.serve(blobKey, resp);

还有其他代码吗?请建议我。

0 个答案:

没有答案