As of April 12th, you must go to Progress SupportLink to create new support cases or to access existing cases. Please, bookmark the SupportLink URL and use the new portal to contact the support team.
Hey,
I've used the same piece of code, upload is successful but the image file uploaded turns out to be invalid.
What might be the reason?
How do I download it?
Please help its very urgent!
Nidhi:
I'm not entirely sure what you mean by this? Downloading files via the datastore is covered in depth in our guides (Under the heading "fetching". For example: http://devcenter.kinvey.com/html5/guides/datastore#Fetching ).
If you can be more specific about what you've tried and what issues you are running into I'm sure this is something we can get figured out. Can you reply with more information including code that you've tried?
Thanks,
This is the Upload code:
FileMetaData metadata = new FileMetaData();
metadata.setPublic(true);
metadata.setFileName(file.getName());
kinveyClient.file().upload(metadata,file, new MetaUploadProgressListener() {
public void onSuccess(Void arg0) {
// TODO Auto-generated method stub
Log.i("TAG", "successfully upload bytes");
s="suc";
list.add(getMetadata().getId());
}
public void onFailure(Throwable error) {
// TODO Auto-generated method stub
Log.e("TAG", "failed to upload bytes.", error);
s="fail";
}
public void progressChanged(MediaHttpUploader uploader) throws IOException {
// TODO Auto-generated method stub
Log.i("TAG", "upload progress: " + uploader.getUploadState());
// all updates to UI widgets need to be done on the UI thread
s="pro";
}
});
download code:
File file=new File(nam);
try {
file.createNewFile();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
FileMetaData meta=new FileMetaData(nam);
FileOutputStream fos=null;
try {
fos = new FileOutputStream(file);
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
kinveyClient.file().download(meta, fos, new DownloaderProgressListener() {
public void onSuccess(Void result) {
Log.i("TAG", "successfully downloaded file");
text1.setText("s");
}
public void onFailure(Throwable error) {
Log.e("TAG", "failed to downloaded file.", error);
text1.setText("f");
}
public void progressChanged(MediaHttpDownloader downloader) throws IOException {
Log.i("TAG", "progress updated: "+downloader.getDownloadState());
// any updates to UI widgets must be done on the UI thread
text1.setText("pro");
}
});
Download is not working at all. And even the uploaded files are invalid. I'm not able to figure out the reason.
And the platform is Android.
I'm working on Android.
This is the upload code:
FileMetaData metadata = new FileMetaData();
metadata.setPublic(true);
metadata.setFileName(file.getName());
kinveyClient.file().upload(metadata,file, new MetaUploadProgressListener() {
public void onSuccess(Void arg0) {
// TODO Auto-generated method stub
Log.i("TAG", "successfully upload bytes");
s="suc";
list.add(getMetadata().getId());
}
public void onFailure(Throwable error) {
// TODO Auto-generated method stub
Log.e("TAG", "failed to upload bytes.", error);
s="fail";
}
public void progressChanged(MediaHttpUploader uploader) throws IOException {
// TODO Auto-generated method stub
Log.i("TAG", "upload progress: " + uploader.getUploadState());
// all updates to UI widgets need to be done on the UI thread
s="pro";
}
});
This is the download code:
File file=new File(nam);
try {
file.createNewFile();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
FileMetaData meta=new FileMetaData(nam);
FileOutputStream fos=null;
try {
fos = new FileOutputStream(file);
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
kinveyClient.file().download(meta, fos, new DownloaderProgressListener() {
public void onSuccess(Void result) {
Log.i("TAG", "successfully downloaded file");
text1.setText("s");
}
public void onFailure(Throwable error) {
Log.e("TAG", "failed to downloaded file.", error);
text1.setText("f");
}
public void progressChanged(MediaHttpDownloader downloader) throws IOException {
Log.i("TAG", "progress updated: "+downloader.getDownloadState());
// any updates to UI widgets must be done on the UI thread
text1.setText("pro");
}
});
The files are not downloading, and even the ones uploaded are invalid files (images). Not able to figure out the reason. It would be great, if you could help.
Nidhi:
Did you check out the security guide for "globally readable" files? http://devcenter.kinvey.com/android/guides/security#GlobalAccessControl I think that's likely what you are after.
Thanks,
But I'm not working with entities!
Nidhi:
Files are treated as entities within Kinvey.
Can you attempt to manually download one of the files you upload and ensure it's in the format you expect it to be in? Would you be comfortable sharing the code that you're using to create / get the file for uploading? Specifically where you define the file used in the following line of code:
kinveyClient.file().upload(metadata,file, new MetaUploadProgressListener() {
Thanks,
Davide Neri
FileMetaData metadata = new FileMetaData();
metadata.setPublic(true);
metadata.setFileName("picture");
java.io.File file = new java.io.File(getRealPathFromURI(data.getData()));
try {
file.createNewFile();
} catch (IOException e) {
e.printStackTrace();
}
getClient().file().upload(metadata, file, new UploaderProgressListener() {
@Override
public void onSuccess(Void result) {
Log.i("UPLOAD", "successfully upload file");
}
@Override
public void onFailure(Throwable error) {
Log.e("UPLOAD", "failed to upload file.", error);
}
@Override
public void progressChanged(MediaHttpUploader uploader) throws IOException {
Log.i("UPLOADING", "upload progress: " + uploader.getUploadState());
}
});
If I comment out metadata.setPublic(true); the code works fine, ends up in onSuccess() ...but my file is private.
If I un-comment the "setPublic" line, I have an error thrown back:
failed to upload file.
java.lang.IllegalArgumentException: invalid value for field
at java.lang.reflect.Field.setField(Native Method)
at java.lang.reflect.Field.set(Field.java:588)
at com.google.api.client.util.FieldInfo.setFieldValue(FieldInfo.java:247)
at com.google.api.client.util.FieldInfo.setValue(FieldInfo.java:208)
at com.google.api.client.util.GenericData.put(GenericData.java:103)
at com.kinvey.java.core.MediaHttpUploader.upload(MediaHttpUploader.java:340)
at com.kinvey.java.core.AbstractKinveyClientRequest.executeUnparsed(AbstractKinveyClientRequest.java:334)
at com.kinvey.java.core.AbstractKinveyClientRequest.executeUnparsed(AbstractKinveyClientRequest.java:285)
at com.kinvey.java.core.AbstractKinveyClientRequest.execute(AbstractKinveyClientRequest.java:355)
at com.kinvey.android.AsyncFile$FileUpload.executeAsync(AsyncFile.java:339)
at com.kinvey.android.AsyncFile$FileUpload.executeAsync(AsyncFile.java:288)
at com.kinvey.android.AsyncClientRequest.doInBackground(AsyncClientRequest.java:58)
at android.os.AsyncTask$2.call(AsyncTask.java:287)
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305)
at java.util.concurrent.FutureTask.run(FutureTask.java:137)
at com.kinvey.android.AsyncClientRequest$KinveySerialExecutor$1.run(AsyncClientRequest.java:121)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1076)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:569)
at java.lang.Thread.run(Thread.java:856)
Am I doing anything wrong?
As an alternative, but less clean, option... is there a way I can retrieve the file's ID?
This way I can try calling "blob" once again to set that file public.