blobstore error

Venom84

Baseband Member
Messages
31
Location
Eire
I'm learning AWS and am having problem with a simple upload servlet. As far as I can see everything is fine except for the getUploadedBlobs(req); has a line though it in eclipse. This is the message given

Deprecated. Use getUploads instead. Note that getUploadedBlobs does not handle cases where blobs have been uploaded using the multiple="true" attribute of the file input form element. Returns the BlobKey for any files that were uploaded, keyed by the upload form "name" field. This method should only be called from within a request served by the destination of a createUploadUrl call.

I then get a server error when I try to upload a file. I found a tutorial site and my code seems a complete match.
https://cloud.google.com/appengine/docs/java/blobstore/

I've been scratching my head over this for ages now and can't see the problem, any help would be really appreciated.

Code:
package ie.itb.l.a

import java.io.IOException;
import java.util.Map;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.google.appengine.api.blobstore.BlobKey;
import com.google.appengine.api.blobstore.BlobstoreService;
import com.google.appengine.api.blobstore.BlobstoreServiceFactory;

public class Upload extends HttpServlet 
{
	private static final long serialVersionUID = 1L;
    private BlobstoreService blobstoreService = BlobstoreServiceFactory.getBlobstoreService();

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

        @SuppressWarnings("deprecation")
		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());
        }
    }
}
 
What's the error you get?

If the function is only deprecated then it should still work. However the Eclipse editor could be using an older version of JDK than what you're compiling with.

You really should look into using the newer method though. Eventually those deprecated methods are completely removed and your code will be broken.
 
Ah I never extended the serve class to have HttpServlet, its always the same, I get stuck on something for ages and when I finally check with someone else it sticks out like a sore thumb. Thanks for replying Baez.
 
Back
Top Bottom