【问题标题】:"Please use multipart." When uploading to upload URL from google app engine“请使用多部分。”从谷歌应用引擎上传上传网址时
【发布时间】:2016-12-22 21:51:17
【问题描述】:

我从部署的谷歌应用程序中以编程方式获得了上传 uRL。但是我不断收到以下响应...我缺少什么类型的参数?

Bad content type.  Please use multipart.
2016-08-16 09:25:34 ERROR PayitWebClientApp:207 - 400 Bad Request
Bad content type.  Please use multipart.
    at com.google.api.client.http.HttpRequest.execute(HttpRequest.java:1054)
    at com.vanitysoft.payit.PayitInvokeAuthApp.generateUploadUr(PayitInvokeAuthApp.java:198)
    at com.vanitysoft.payit.PayitInvokeAuthApp.main(PayitInvokeAuthApp.java:217)

这是代码:

      MultipartContent content = new MultipartContent().setMediaType(
                new HttpMediaType("multipart/form-data")
                        .setParameter("boundary", "__END_OF_PART__"));

        FileContent fileContent = new FileContent(
               "multipart/related", file);
        MultipartContent.Part part = new MultipartContent.Part(fileContent);
        part.setHeaders(new HttpHeaders().set(
                "Content-Disposition", 
                String.format("form-data; name=\"content\"; filename=\"%s\"", file.getName())));
        content.addPart(part);

      httpRequest = httpRequestFactory.buildPostRequest(new GenericUrl(uploadItem.getUploadUrl()) ,fileContent);     
      LOGGER.info("upload...[" + uploadItem.getUploadUrl() +"]");
      httpResponse = httpRequest.execute();
      LOGGER.info("Upload complete");
      Assert.isTrue(httpResponse.getStatusCode() == 200, IOUtils.toString(httpResponse.getContent()));      

      LOGGER.info( "Success[" + httpResponse.getContent() +"]" );

【问题讨论】:

    标签: google-app-engine blobstore


    【解决方案1】:

    <form> 标签上缺少enctype="multipart/form-data"

    检查这个答案:Why is form enctype=multipart/form-data required when uploading a file?

    【讨论】:

    • 您好,我的客户端是一个 java 应用程序。您是什么意思将其添加到“表单标签”?我是否将其添加到 Content-Diposition 标头?
    【解决方案2】:

    Opps,错字:,我需要使用“内容”而不是文件内容

    httpRequest = httpRequestFactory.buildPostRequest(new GenericUrl(uploadItem.getUploadUrl()) ,content);

    【讨论】:

      猜你喜欢
      • 2023-03-25
      • 2012-05-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-06-06
      • 2012-06-09
      • 2012-12-01
      • 1970-01-01
      相关资源
      最近更新 更多