我对Uploadcare非常陌生。我正在尝试从Uploadcare检索文件UUID,然后使用该UUID将映像复制到我的S3存储桶中。我正在使用git-hub:here上可用的Uploadcare API。

该代码非常易于实现。这是我所拥有的:

package javaapplication2;

import com.uploadcare.api.Client;
import com.uploadcare.data.CopyFileData;
public class UploadAPITest {

public static void main(String[] args) {

    Client client = new Client("mypublicKey", "myprivateKey");
    CopyFileData copyFile = client.copyFile("d5e97aca-f6d9-47ea-8c76-1fe36d093b2d", "messagePicUploadCenter");
    System.out.println("result: " + copyFile.result);
}


这段代码编译没有问题。但是,当我运行它时,这是我看到的错误:

enterException in thread "main"
com.uploadcare.exceptions.UploadcareNetworkException: Network failure!
at com.uploadcare.api.RequestHelper.executeQuery(RequestHelper.java:108)
at com.uploadcare.api.Client.copyFile(Client.java:221)
at javaapplication2.UploadAPITest.main(UploadAPITest.java:25)

Caused by: com.fasterxml.jackson.databind.JsonMappingException: Can not instantiate value of type [simple type, class com.uploadcare.data.FileData] from String value; no single-String constructor/factory method (through reference chain: com.uploadcare.data.CopyFileData["result"])
at com.fasterxml.jackson.databind.deser.std.StdValueInstantiator._createFromStringFallbacks(StdValueInstantiator.java:422)
at com.fasterxml.jackson.databind.deser.std.StdValueInstantiator.createFromString(StdValueInstantiator.java:298)
at com.fasterxml.jackson.databind.deser.BeanDeserializer.deserializeFromString(BeanDeserializer.java:424)
at com.fasterxml.jackson.databind.deser.BeanDeserializer.deserialize(BeanDeserializer.java:129)
at com.fasterxml.jackson.databind.deser.SettableBeanProperty.deserialize(SettableBeanProperty.java:375)
at com.fasterxml.jackson.databind.deser.impl.FieldProperty.deserializeAndSet(FieldProperty.java:107)
at com.fasterxml.jackson.databind.deser.BeanDeserializer.deserializeFromObject(BeanDeserializer.java:308)
at com.fasterxml.jackson.databind.deser.BeanDeserializer.deserialize(BeanDeserializer.java:121)
at com.fasterxml.jackson.databind.ObjectMapper._readMapAndClose(ObjectMapper.java:2796)
at com.fasterxml.jackson.databind.ObjectMapper.readValue(ObjectMapper.java:1942)
at com.uploadcare.api.RequestHelper.executeQuery(RequestHelper.java:106)
... 2 more


Java结果:1

但是,在发生错误之前,我确实收到Uploadcare的回复:
{“类型”:“ URL”,“结果”:“ s3://photopatch-upload/messageImgs/d5e97aca-f6d9-47ea-8c76-1fe36d093b2d/uniqueness.jpg”}

所以我知道我已经正确连接了Uploadcare,因为该图像实际上是
复制。但是在复制之后,返回的JSON可能格式不正确或某种原因(我在这里猜测)。

有没有其他人遇到这个问题,或者对我有什么建议?我真的很感激。我喜欢这项服务,而且我认为问题与com.faster.jackson.databind库有关。这是我在这个简单项目中使用的库的图片:http://s3.postimg.org/n37i2ts5f/image.png

最佳答案

尝试使用

System.out.println("result: " + copyFile);

copyFile而不是copyFile.result,它是没有FileData方法的toString()实例。

10-06 02:30