我在嘗試使用Parse API上載服務器上的圖片時遇到問題。我可以從服務器讀取數據並更新任何列上的數據,除了上傳圖像。使用解析API上傳圖片
我從設備選擇了圖像和ImageView的顯示..
// Move to first row
cursor.moveToFirst();
int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
String imgDecodableString = cursor.getString(columnIndex);
cursor.close();
ImageView imageView = (ImageView) findViewById(R.id.imageView);
Bitmap bitmap = ((BitmapDrawable) imageView.getDrawable()).getBitmap();
// Set the Image in ImageView after decoding the String
imageView.setImageURI(selectedImage);
Picasso.with(this).load(selectedImage).fit().centerCrop().into(imageView);
//resizing the image part 2
ByteArrayOutputStream baos = new ByteArrayOutputStream();
//to Compress the image
//Quality Accepts 0 - 100
//0 = MAX Compression (Least Quality which is suitable for Small images)
//100 = Least Compression (MAX Quality which is suitable for Big images)
bitmap.compress(Bitmap.CompressFormat.PNG, 0, baos);
//uploading the image to server
byte[] imageInByte = imgDecodableString.getBytes();
final ParseFile bitmapFile = new ParseFile(imageInByte);
bitmapFile.saveInBackground();
//current user is already logged in.
ParseObject userDisplayImage = new ParseObject("UserDisplayImage");
userDisplayImage.put("photo", bitmapFile);
userDisplayImage.saveInBackground();
你應該嘗試在獲得來自服務器的響應是'saveInBackground()''使用saveInBackground(新SaveCallback {...})'。此外,請務必使用以下命令來檢查解析異常:「if(e!= null)e.printStacktrace();' – ZeekHuge
我做了並仍然得到相同的錯誤 - 吐司」空照片文件「。我認爲從服務器。 – MAT