如何在android中使用解析api在解析服务器中上传图像

如何在android中使用解析api在解析服务器中上传图像

本文介绍了如何在android中使用解析api在解析服务器中上传图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在 android 中的解析云服务器中上传图像.但我做不到.

我尝试了以下代码:

 Drawable drawable = getResources().getDrawable(R.drawable.profilepic) ;位图 bitmap = (Bitmap)(Bitmap)drawable()ByteArrayOutputStream 流 = new ByteArrayOutputStream();bitmap.compress(Bitmap.CompressFormat.PNG, 100, 流);byte[] data = stream.toByteArray();ParseFile imageFile = new ParseFile("image.png", data);imageFile.saveInBackground();

请告诉我该怎么做.

我添加了一个悬赏来寻找这个常见问题的最佳最终代码

解决方案

在后台保存 ParseObject

//解析对象ParseObject pObject = new ParseObject("ExampleObject");pObject.put("myNumber", number);pObject.put("myString", name);pObject.saveInBackground();//异步,无回调

使用回调在后台保存

pObject.saveInBackground(new SaveCallback() {@覆盖公共无效完成(解析异常前){if (ex == null) {isSaved = true;} 别的 {//失败的isSaved = false;}}});

save...() 方法的变体包括:

 saveAllinBackground() 保存带有或不带有回调的 ParseObject.saveAll(List objects) 保存 ParseObjects 的列表.saveAllinBackground(List objects) 将 ParseObjects 的列表保存在背景.saveEventually() 允许您在将来的某个时间将数据对象保存到服务器;用如果当前无法访问 Parse 云,则使用此方法.

一旦 ParseObject 成功保存在云上,它就会被分配一个唯一的 Object-ID.这个 Object-ID 非常重要,因为它唯一标识了 ParseObject 实例.例如,您可以使用对象 ID 来确定对象是否已成功保存在云中、检索和刷新给定的 Parse 对象实例以及删除特定的 ParseObject.

我希望你能解决你的问题..

I want to upload an image in parse cloud server in android. But I am unable to do so.

I have tried the following code:

    Drawable drawable = getResources().getDrawable(R.drawable.profilepic) ;
    Bitmap bitmap = (Bitmap)(Bitmap)drawable()
    ByteArrayOutputStream stream = new ByteArrayOutputStream();
    bitmap.compress(Bitmap.CompressFormat.PNG, 100, stream);
    byte[] data = stream.toByteArray();

    ParseFile imageFile = new ParseFile("image.png", data);
    imageFile.saveInBackground();

Please let me know how can I do it.


I've added a bounty to find the best definitive code for this common problem

解决方案

Save ParseObject in the background

Save in the background with callback

Variations of the save...() method include the following:

Once a ParseObject has been successfully saved on the Cloud, it is assigned a unique Object-ID. This Object-ID is very important as it uniquely identifies that ParseObject instance. You would use the Object-ID, for example, to determine if the object was successfully saved on the cloud, for retrieving and refreshing a given Parse object instance, and for deleting a particular ParseObject.

I hope you will solve your problem..

这篇关于如何在android中使用解析api在解析服务器中上传图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-01 17:25