Error while uploading file through servlet on Deployed app

93 views
Skip to first unread message

Iwansyah Putra

unread,
Sep 12, 2017, 9:03:46 AM9/12/17
to Google App Engine
I get following error when I try to upload file to Google Cloud Storage through servlet using Google Client Library. The wierd part is file uploading process run okay when I do at local development server, error happened in deployed version of the app

java.lang.IllegalStateException: No multipart config for servlet

and this is my uploading servlet 

import com.google.cloud.storage.*;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.MultipartConfig;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.Part;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

@MultipartConfig()
public class GCSAccessServlet extends HttpServlet {

private static final String BUCKET_NAME = System.getenv("bucketName");
private static Storage storage = null;

@Override
public void init() {
storage = StorageOptions.getDefaultInstance().getService();

}

@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

if (BUCKET_NAME.equals("") || BUCKET_NAME == null) {
System.out.println("Bucket is not found (null / empty name)");
}
Bucket bucket = storage.get(BUCKET_NAME);
req.setAttribute("bucketName", bucket.getName());

resp.setContentType("text/html");
RequestDispatcher jsp = req
.getRequestDispatcher("upload.jsp");
jsp.forward(req, resp);
}

@Override
public void doPost(HttpServletRequest req, HttpServletResponse resp) throws IOException,
ServletException {
final Part filePart = req.getPart("file");
final String fileName = filePart.getSubmittedFileName();

// Modify access list to allow all users with link to read file
List<Acl> acls = new ArrayList<>();
acls.add(Acl.of(Acl.User.ofAllUsers(), Acl.Role.READER));
// the inputstream is closed by default, so we don't need to close it here
Blob blob =
storage.create(
BlobInfo.newBuilder(BUCKET_NAME, fileName).setAcl(acls).build(),
filePart.getInputStream());

// return the public download link
resp.getWriter().print(blob.getMediaLink());
}

}

I couldn't find explanation about this problem.

Thanks.

Yannick (Cloud Platform Support)

unread,
Sep 12, 2017, 10:50:09 AM9/12/17
to Google App Engine
Hello Iwansyah, note that this group is intended for discussion on App Engine and not code troubleshooting, which is best done by posting a question on Stack Overflow using one of the tags monitored by our community technical support team. If you do so I would advise that you add as much information as possible about your application to allow for reproducing the issue, including your pom.xml.

A quick search on the web reveals that this error is usually linked to having an out of date configuration or using the wrong dependencies.

Iwansyah Putra

unread,
Sep 13, 2017, 5:50:51 AM9/13/17
to Google App Engine
Thank you for the response.
Reply all
Reply to author
Forward
0 new messages