Start a new topic

IllegalArguementException when uploading a file

I am trying to upload a file to Kinvey but I am getting an IllegalArguementException . The code I use to upload the file is from the Java guide(http://devcenter.kinvey.com/java/guides/files#Uploading)



InputStream stream = new ByteArrayInputStream(json.getBytes("UTF-8"));



mKinveyClient.file().uploadBlocking(metadata, stream, new UploaderProgressListener() {

@Override

public void onSuccess(Void result) {

System.out.println("upload success!");

}

@Override

public void onFailure(Throwable error) {

System.out.println("upload progress change!");

}

@Override

public void progressChanged(MediaHttpUploader uploader) throws IOException {

System.out.println("upload progress change -> " + uploader.getUploadState());

}

});



Now when I switch the metadata with a string, everything works fine. The error I am getting is this:

Exception in thread "main" java.lang.IllegalArgumentException: Can not set java.util.List field com.google.api.client.http.HttpHeaders.cacheControl to java.lang.String

at sun.reflect.UnsafeFieldAccessorImpl.throwSetIllegalArgumentException(Unknown Source)

at sun.reflect.UnsafeFieldAccessorImpl.throwSetIllegalArgumentException(Unknown Source)

at sun.reflect.UnsafeObjectFieldAccessorImpl.set(Unknown Source)

at java.lang.reflect.Field.set(Unknown Source)

at com.google.api.client.util.FieldInfo.setFieldValue(FieldInfo.java:245)

at com.google.api.client.util.FieldInfo.setValue(FieldInfo.java:206)

at com.google.api.client.util.GenericData.put(GenericData.java:103)

at com.kinvey.java.core.MediaHttpUploader.upload(MediaHttpUploader.java:365)

at com.kinvey.java.core.AbstractKinveyClientRequest.executeUnparsed(AbstractKinveyClientRequest.java:347)

at com.kinvey.java.core.AbstractKinveyClientRequest.executeUnparsed(AbstractKinveyClientRequest.java:295)

at com.kinvey.java.core.AbstractKinveyClientRequest.execute(AbstractKinveyClientRequest.java:368)

at com.kinvey.nativejava.File.uploadBlocking(File.java:135)



So I am thinking there is an error in the metadata upload method.

It works! I can send upload a file to the backend if I set metadata.setPublic(true);. My question is why would I need to? I set the access of files to



access.setGloballyReadable(true);

access.setGloballyWriteable(true);



Doing this allowed other users to access and manipulate the files. So setting the file to public seems redundant. Is there something I am missing?
Hey,



check out v 2.6.12 of the java library, that contains the fix this issue-- try it and let me know how it goes!



http://devcenter.kinvey.com/java/downloads
Hey,



thanks for reporting this, it is a bug in the library. When setting the public flag to true, the library adds extra headers to the request but there have been recent changes in what GCS is expecting.



I am working through the fix now and will push out a release later this week.



Specifically it seems that the error is related to "metadata.setPublic(true);". When i comment out that line it works.
Login or Signup to post a comment