使用解析API

时间:2017-09-22 20:43:42

标签: android

我无法尝试使用Parse 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();

1 个答案:

答案 0 :(得分:0)

在您的代码中:

p

final ParseFile bitmapFile = new ParseFile(imageInByte); bitmapFile.saveInBackground(); 在后​​台线程中上传,因此当您到达下一个语句时:

bitmapFile

ParseObject userDisplayImage = new ParseObject("UserDisplayImage"); userDisplayImage.put("photo", bitmapFile); userDisplayImage.saveInBackground (...); 未完全上传,因此bitmapFile无法指向它。

您可以尝试以下方法进行修复:

userDisaplyImage