upload a file using spring MultipartFile and google app engine

前端 未结 1 1285
粉色の甜心
粉色の甜心 2020-12-11 23:03

I have been trying to upload a file by using MVC and Google App engine. Every time i am getting the error like

Expected MultipartHttpServletRequest: is a Mu

相关标签:
1条回答
  • 2020-12-11 23:36

    The following method will return a callback URL on which you need to post your file(s).

    Upload Url Method

    @RequestMapping(value = "/uploadurl", method = RequestMethod.GET)
    public String getImageUploadUrl() {
        modelMap.addAttribute('uploadUrl',blobstoreService.createUploadUrl("/imageupload));
        return "upload";
    }
    

    Following is the JSP snippet where you will embed your code. I am putting the URL in form tag using JSTL.

    JSP Page

    <form action="${uploadUrl}" method="POST" enctype="multipart/form-data">
        <input type="file" name="myFile" multiple="multiple" />
    </form>
    

    Upload Handler Method

    @ResponseBody
    @RequestMapping(value = "/imageupload", method = RequestMethod.POST)
    public void getUploadedImagesUrls(HttpServletRequest request){
        Map<String, List<BlobKey>> blobs = blobstoreService.getUploads(request);
        List<BlobKey> blobKeys = blobs.get("myFile[]");
        if (blobKeys == null) {
            return null;
        } else {
            for(BlobKey blobKey : blobKeys){
                // ImagesService services = ImagesServiceFactory.getImagesService();
                // ServingUrlOptions serve = ServingUrlOptions.Builder.withBlobKey(blobKey);
                // String imageUrl = services.getServingUrl(serve);
                BlobInfoFactory blobInfoFactory = new BlobInfoFactory();
                BlobInfo info = blobInfoFactory.loadBlobInfo(blobKey);
                System.out.println("Image URL : "+imageUrl);
                System.out.println("Image FileName : "+info.getFilename());
            }
        }
    }
    
    0 讨论(0)
提交回复
热议问题