[英]Get file from parseObject
這是一個較少的Android問題和更多Parse.com問題,但我需要你的幫助:
我在Parse.com的應用程序表中有一個圖像文件
文件還可以,我可以手動下載並觀看。
但是當我試圖使用我從服務器獲得的parseObject來獲取它時,我得到“null”
碼:
byte[] imageFile = parseObject.getBytes(Statics.COL_IMAGE_FILE);
我究竟做錯了什么?
ps:我可以在parseObject“estimatedData”字段中看到圖像文件數據/鏈接,但無法得到他。
如果Statics.COL_IMAGE_FILE
是File
列,則應執行以下操作以獲取byte []:
ParseFile imageFile = (ParseFile)parseObject.get(Statics.COL_IMAGE_FILE);
imageFile.getDataInBackground(new GetDataCallback() {
public void done(byte[] data, ParseException e) {
if (e == null) {
// data has the bytes for the image
} else {
// something went wrong
}
}
});
從我的應用程序中查看此代碼段。 外部查詢返回與文件關聯的對象,內部查詢返回該對象的文件。 希望能幫助到你。
ParseQuery<ParseObject> query = ParseQuery.getQuery("ClassName");
query.whereEqualTo("Column", "Your_variable");
query.getFirstInBackground(new GetCallback<ParseObject>() {
public void done(ParseObject object, ParseException e) {
if (object != null) {
ParseFile file = (ParseFile)object.get("File_Coulumn");
file.getDataInBackground(new GetDataCallback() {
public void done(byte[] data, ParseException e) {
if (e == null) {
bitmap=BitmapFactory.decodeByteArray(data, 0, data.length);
//use this bitmap as you want
} else {
// something went wrong
}
}
});
} else {
Toast.makeText(getApplicationContext(), "Exception", Toast.LENGTH_SHORT) .show();
}
}
});
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.