Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

for循环上传的时候,报错。 #1

Open
vinfolhu opened this issue Apr 25, 2016 · 1 comment
Open

for循环上传的时候,报错。 #1

vinfolhu opened this issue Apr 25, 2016 · 1 comment

Comments

@vinfolhu
Copy link

vinfolhu commented Apr 25, 2016

核心代码如下:

public static String uploadFile(String weixinId, long currentTimeStamp, InputStream inputs) {
        String ACCESS_KEY = QiniuStaticConfig.getQiniuAccessKey();
        String SECRET_KEY = QiniuStaticConfig.getQiniuSecretKey();
        String bucketName = QiniuStaticConfig.getQiniuBucketName();
        String baseUrl = QiniuStaticConfig.getQiniuShowHost();
//      System.out.println(UUID.randomUUID().toString().replaceAll("-","").length());

        String qiNiuShowUrl = "";
        Mac mac = new Mac(ACCESS_KEY, SECRET_KEY);
        // 请确保该bucket已经存在
        try {
            String fileKey = weixinId+UUID.randomUUID().toString(); 

            PutPolicy putPolicy = new PutPolicy(bucketName);
            putPolicy.saveKey = fileKey;

            String uptoken = putPolicy.token(mac);

            PutExtra extra = new PutExtra();

            InputStream is = inputs;

            PutRet ret = IoApi.Put(uptoken, fileKey, is, extra);
            qiNiuShowUrl = String.format("%s%s", baseUrl, fileKey);
            log.info("\n\t\tret="+JSONObject.toJSONString(ret));
            is.close();
            if(ret.getException()==null){
                return null;
            }
        } catch (Exception e) {
            log.error(e.getMessage());
            return null;
        } 
        return qiNiuShowUrl;
    }

后台一直输入如下错:

"response":"{\"error\":\"invalid multipart format: unexpected EOF\"}","statusCode":400
@icattlecoder
Copy link
Owner

循环调用uploadFile吗?EOF一般是你的输入流有问题

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants