0

I'm very new to Uploadcare. I am trying to retrieve a file UUID from Uploadcare, then use that UUID to copy the image to my S3 storage bucket. I am using the Uploadcare API available on git-hub:here.

The code is super easy to implement. Here's what I have:

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);
}

This code compiles with no problem. Yet when I run it, this is the error I see:

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 Result: 1

Before the error, however, I do get a response from Uploadcare: {"type":"url","result":"s3://photopatch-upload/messageImgs/d5e97aca-f6d9-47ea-8c76-1fe36d093b2d/uniqueness.jpg"}

So I know I've connected with Uploadcare correctly because the image is in fact copied. But after the copy, the JSON that comes back may be malformed or something (I'm guessing here).

Has anyone else had this issue, or have some advice for me? I would really appreciate it. I love this service, and I think the issue has more to do with the com.faster.jackson.databind library. Here's a picture of the libraries I'm using in this simple project: http://s3.postimg.org/n37i2ts5f/image.png

tkp432
  • 13
  • 1
  • 3
  • 1
    there probably is a network issue, as `UploadcareNetworkException` is raised, you may want to look into it and find what causes this. – Dmitry Mukhin Feb 28 '15 at 09:55
  • @mojo I added a edit to my above question just to let everyone know that the transfer/copy is occuring, but there is a problem when the response of the successful transfer/copy comes back. At this point I'm using the REST API and that is working just fine. But I would like to get the Java library functioning. – tkp432 Feb 28 '15 at 15:51
  • aha! this is not a network issue, System.out.println cannot output copyFile.result. You may need to cast it to something else or use other property – Dmitry Mukhin Feb 28 '15 at 20:06

1 Answers1

1

Try using

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

i.e. copyFile instead of copyFile.result which is an instance of FileData that doesn't have toString() method.

Dmitry Mukhin
  • 6,649
  • 3
  • 29
  • 31
  • I tried that...no luck. The program is crashing before it even reaches the system.out.print(). When I remove the System.out.print(), The program still crashes with the same error. – tkp432 Mar 01 '15 at 18:10