how to upload a audio file using REST webservice in Google App Engine for Java

Posted by sathya on Stack Overflow See other posts from Stack Overflow or by sathya
Published on 2012-12-07T10:35:54Z Indexed on 2012/12/08 5:04 UTC
Read the original article Hit count: 207

Am using google app engine with eclipse IDE and trying to upload a audio file. I used the File Upload in Google App Engine For Java and can able to upload the file successfully. Now am planning to use REST web service for it. I had analyzed in developers.google but i failed. Can anyone suggest me how to implement REST Web services in google app engine using Eclipse.

The code google provided is shown below,

// file Upload.java
public class Upload extends HttpServlet {

private BlobstoreService blobstoreService = BlobstoreServiceFactory.getBlobstoreService();

public void doPost(HttpServletRequest req, HttpServletResponse res)
    throws ServletException, IOException {

 Map<String, BlobKey> blobs = blobstoreService.getUploadedBlobs(req);

BlobKey blobKey = blobs.get("myFile");

if (blobKey == null) {

res.sendRedirect("/");
 } else {
res.sendRedirect("/serve?blob-key=" + blobKey.getKeyString());
}}}

// file Serve.java

public class Serve extends HttpServlet {
private BlobstoreService blobstoreService = BlobstoreServiceFactory.getBlobstoreService();
public void doGet(HttpServletRequest req, HttpServletResponse res)
throws IOException {
BlobKey blobKey = new BlobKey(req.getParameter("blob-key"));
 blobstoreService.serve(blobKey, res);
}}


// file index.jsp

<%@ page import="com.google.appengine.api.blobstore.BlobstoreServiceFactory" %>
<%@ page import="com.google.appengine.api.blobstore.BlobstoreService" %>
<% BlobstoreService blobstoreService = BlobstoreServiceFactory.getBlobstoreService(); %>

 <form action="<%= blobstoreService.createUploadUrl("/upload") %>" method="post" enctype="multipart/form-data">
<input type="file" name="myFile">
<input type="submit" value="Submit">
</form>



// web.xml

<servlet>
<servlet-name>Upload</servlet-name>
<servlet-class>Upload</servlet-class>
</servlet>

<servlet>
<servlet-name>Serve</servlet-name>
<servlet-class>Serve</servlet-class>
</servlet>

<servlet-mapping>
<servlet-name>Upload</servlet-name>
<url-pattern>/upload</url-pattern>
</servlet-mapping>

<servlet-mapping>
<servlet-name>Serve</servlet-name>
<url-pattern>/serve</url-pattern>
</servlet-mapping>

Now how to provide a rest web service for the above code. Kindly suggest me an idea.

© Stack Overflow or respective owner

Related posts about java

Related posts about web-services