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
<https://cloud.google.com/support/docs/stackexchange> 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.
On Tuesday, September 12, 2017 at 9:03:46 AM UTC-4, Iwansyah Putra wrote:
>
> 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.
>
--
You received this message because you are subscribed to the Google Groups
"Google App Engine" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/google-appengine.
To view this discussion on the web visit
https://groups.google.com/d/msgid/google-appengine/29394b06-5144-49df-9c65-7da5b2ce507f%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.