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

UploadManager.filterParam 与FormUploader. buildParams() 逻辑冲突 #467

Open
hzdjulytech opened this issue Jan 3, 2020 · 6 comments
Open
Labels
documentation Improvements or additions to documentation.

Comments

@hzdjulytech
Copy link

[7.2.0, 7.2.99]
FormUploader. buildParams()
中 Object object = params.get("filename");
无法取到自定义值,已被 UploadManager.filterParam 中过滤掉了
且自定义名称优先级不应低于默认值 filename = file.getName();

@forrest-mao forrest-mao added the documentation Improvements or additions to documentation. label Jul 21, 2020
@forrest-mao
Copy link

抱歉,如果是自定义的参数值 key 需要以x:为前缀来进行定义,例如 https://github.com/qiniu/java-sdk/blob/master/src/main/java/com/qiniu/storage/UploadManager.java#L136 的描述,具体我们来进行文档的补充

@forrest-mao
Copy link

仅七牛内部员工可见:https://jira.qiniu.io/browse/TS-986

@peteryuanpan
Copy link
Contributor

pr:#468

@howareyouo
Copy link

howareyouo commented May 4, 2022

那请问怎么才能使用这个$(fname)变量,我无论怎么设置,都获取不到。

还是说这个变量不是用来设置回传原文件名的? 如果 fnamekey, hash 一模一样的话,我拿它有什么用?

如果不是用来存原文件名的,你取名叫 f(ile)name 不是误导人?

image
代码是这样的:

    String path = "C:\\Users\\hunan\\Downloads\\taylor-swift-1.jpg";
    File file = new File(path);
    FileInputStream fi = new FileInputStream(file);
    byte[] bytes = StreamUtils.copyToByteArray(fi);
    StringMap params = new StringMap();
    params.put("filename", file.getName());
    params.put("fileName", file.getName());
    params.put("x:fileName", file.getName());
    params.put("x:filename", file.getName());
    Response put = um.put(bytes, null, uptoken(), params, null, false);
    System.out.println(put.bodyString());

returnBody 是这样的

  policy.put("returnBody", "{\"key\":\"$(key)\",\"hash\":\"$(etag)\",\"fname\":\"$(fname)\",\"ext\":\"$(ext)\"}");

返回的是这样的:

{"key":"Fg0Zq1_buk-Ah_g0rIReMoomyslw","hash":"Fg0Zq1_buk-Ah_g0rIReMoomyslw","fname":"defaultFilename","ext":".jpg"}

@YangSen-qn
Copy link
Contributor

YangSen-qn commented May 5, 2022

@howareyouo 官方文档声明的是 api 的接口,针对 java sdk 的使用姿势您可以使用自定义变量的方式,即 :

    StringMap params = new StringMap();
    params.put("x:filename", file.getName());
    Response put = um.put(bytes, null, uptoken(), params, null, false);

这样设置再返回的信息中,会增加一条 json 数据
java

@howareyouo
Copy link

@howareyouo 官方文档声明的是 api 的接口,针对 java sdk 的使用姿势您可以使用自定义变量的方式,即 :

    StringMap params = new StringMap();
    params.put("x:filename", file.getName());
    Response put = um.put(bytes, null, uptoken(), params, null, false);

这样设置再返回的信息中,会增加一条 json 数据 java

已经解决了,感觉用 saveKey 是最好的方案了

七牛文档写的都是点到为止,其余都靠自己摸索,真心累啊

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

No branches or pull requests

5 participants