Start a new topic

In version "kinvey-android-2.10.3" the method linkedData...save not working.

In version "kinvey-android-2.10.3" o método linkedData...save not working. The image is saved but the entity does not.



D/Kinvey - Client: updateEntity.getMeta().isGloballyReadable() = true

12-10 10:23:28.971 29017-29017/com.kinvey.sample.statusshare I/Kinvey - Client: there is an attachment!

12-10 10:23:28.976 29017-29017/com.kinvey.sample.statusshare I/Choreographer: Skipped 184 frames! The application may be doing too much work on its main thread.

12-10 10:23:29.406 29017-29188/com.kinvey.sample.statusshare D/HttpTransport: -------------- REQUEST --------------

PUT https://baas.kinvey.com/blob/kid_bJTVk8LY5l/5668169429ff85835d0451f8_attachment_1449750208974.png

Accept-Encoding: gzip

Authorization: <Not Logged>

Content-Type: application/json; charset=UTF-8

User-Agent: android-kinvey-http/2.10.3

x-kinvey-content-type: application/octet-stream

x-kinvey-api-version: 3

x-kinvey-device-information: samsung/GT-I9500 Android 5.0.1 20050068-a3ce-377d-beff-2af8da9875fc

Content-Type: application/json; charset=UTF-8

Content-Length: 214

12-10 10:23:29.406 29017-29188/com.kinvey.sample.statusshare D/HttpTransport: curl -v --compressed -X PUT -H 'Accept-Encoding: gzip' -H 'Authorization: <Not Logged>' -H 'Content-Type: application/json; charset=UTF-8' -H 'User-Agent: android-kinvey-http/2.10.3' -H 'x-kinvey-content-type: application/octet-stream' -H 'x-kinvey-api-version: 3' -H 'x-kinvey-device-information: samsung/GT-I9500 Android 5.0.1 20050068-a3ce-377d-beff-2af8da9875fc' -H 'Content-Type: application/json; charset=UTF-8' -d '@-' -- 'https://baas.kinvey.com/blob/kid_bJTVk8LY5l/5668169429ff85835d0451f8_attachment_1449750208974.png' << $$$

12-10 10:23:29.406 29017-29188/com.kinvey.sample.statusshare I/System.out: (HTTPLog)-Static: isSBSettingEnabled false

12-10 10:23:29.416 29017-29188/com.kinvey.sample.statusshare D/HttpTransport: Total: 214 bytes

12-10 10:23:29.416 29017-29188/com.kinvey.sample.statusshare D/HttpTransport: {"_acl":{"gr":true,"gw":false},"_filename":"5668169429ff85835d0451f8_attachment_1449750208974.png","_id":"5668169429ff85835d0451f8_attachment_1449750208974.png","_public":true,"mimeType":"image/png","size":2464470}

12-10 10:23:30.006 29017-29188/com.kinvey.sample.statusshare D/HttpTransport: -------------- RESPONSE --------------

201 Created

Content-Length: 923

Content-Type: application/json; charset=utf-8

Date: Thu, 10 Dec 2015 12:23:29 GMT

Server: ngx_openresty

X-Android-Received-Millis: 1449750210006

X-Android-Response-Source: NETWORK 201

X-Android-Sent-Millis: 1449750209415

X-Kinvey-API-Version: 3

X-Kinvey-Request-Id: 1040512a5c5a4e13800c20b68c33998e

X-Powered-By: Express

12-10 10:23:30.021 29017-29188/com.kinvey.sample.statusshare D/HttpTransport: Total: 923 bytes

12-10 10:23:30.021 29017-29188/com.kinvey.sample.statusshare D/HttpTransport: {"_acl":{"gr":true,"gw":false,"creator":"5668169429ff85835d0451f8"},"_filename":"5668169429ff85835d0451f8_attachment_1449750208974.png","_id":"5668169429ff85835d0451f8_attachment_1449750208974.png","_public":true,"mimeType":"image/png","size":2464470,"_kmd":{"lmt":"2015-12-10T12:23:29.730Z","ect":"2015-12-10T12:23:29.730Z"},"_uploadURL":"http://storage.googleapis.com/bc386d0d15f64e83942faf125abaa2a0/5668169429ff85835d0451f8_attachment_1449750208974.png/5668169429ff85835d0451f8_attachment_1449750208974.png?GoogleAccessId=558440376631@developer.gserviceaccount.com&Expires=1449750239&Signature=Ji%2BK1KptgF7BOkE1hXwToc0S3PcH6iPnYEulbcomvyRLWMUU2WqmnyjviH8NojQC%2FJ5gbWcd36OslZ%2BIX4tr53DGIBLa5gejgXh0rHpLaTGgbMPO22s%2FPpX76UFPHrwaXEeqt4K9V%2FfK97ieV2qHTFJNazCHSp5vDyiscxGmqsA%3D","_expiresAt":"2015-12-10T12:23:59.901Z","_requiredHeaders":{"x-goog-acl":"public-read","Cache-Control":"private, max-age=0, no-transform"}}

12-10 10:23:30.036 29017-29188/com.kinvey.sample.statusshare D/HttpTransport: -------------- REQUEST --------------

PUT http://storage.googleapis.com/bc386d0d15f64e83942faf125abaa2a0/5668169429ff85835d0451f8_attachment_1449750208974.png/5668169429ff85835d0451f8_attachment_1449750208974.png?GoogleAccessId=558440376631@developer.gserviceaccount.com&Expires=1449750239&Signature=Ji%2BK1KptgF7BOkE1hXwToc0S3PcH6iPnYEulbcomvyRLWMUU2WqmnyjviH8NojQC/J5gbWcd36OslZ%2BIX4tr53DGIBLa5gejgXh0rHpLaTGgbMPO22s/PpX76UFPHrwaXEeqt4K9V/fK97ieV2qHTFJNazCHSp5vDyiscxGmqsA%3D

Accept-Encoding: gzip

Cache-Control: private

Cache-Control: max-age=0

Cache-Control: no-transform

x-goog-acl: public-read

Content-Type: application/octet-stream

12-10 10:23:30.036 29017-29188/com.kinvey.sample.statusshare D/HttpTransport: curl -v --compressed -X PUT -H 'Accept-Encoding: gzip' -H 'Cache-Control: private' -H 'Cache-Control: max-age=0' -H 'Cache-Control: no-transform' -H 'x-goog-acl: public-read' -H 'Content-Type: application/octet-stream' -d '@-' -- 'http://storage.googleapis.com/bc386d0d15f64e83942faf125abaa2a0/5668169429ff85835d0451f8_attachment_1449750208974.png/5668169429ff85835d0451f8_attachment_1449750208974.png?GoogleAccessId=558440376631@developer.gserviceaccount.com&Expires=1449750239&Signature=Ji%2BK1KptgF7BOkE1hXwToc0S3PcH6iPnYEulbcomvyRLWMUU2WqmnyjviH8NojQC/J5gbWcd36OslZ%2BIX4tr53DGIBLa5gejgXh0rHpLaTGgbMPO22s/PpX76UFPHrwaXEeqt4K9V/fK97ieV2qHTFJNazCHSp5vDyiscxGmqsA%3D' << $$$

12-10 10:23:30.036 29017-29188/com.kinvey.sample.statusshare I/System.out: (HTTPLog)-Static: isSBSettingEnabled false

12-10 10:23:30.056 29017-29188/com.kinvey.sample.statusshare I/System.out: KnoxVpnUidStorageknoxVpnSupported API value returned is false

12-10 10:23:38.191 29017-29188/com.kinvey.sample.statusshare D/HttpTransport: Total: 2.464.470 bytes (logging first 16.384 bytes)

���y� 7 U ��<?>>�|�*d����wj�� EĽ��:����p{�.l��`�Z����9甒*cm�~\ �+� Zk �?3 � B���ZK))��;��{O)�֠ J�DŽ\��?�މ���֚�^J �J Bx���r���r�! �1���f ��*��ݡD�Vl� � ��gJ���<������LD!X)����RJٶ���; �j� *��;ސ, �}�x@ !�5o��5 ��UCkm۶޻ �����,�R� 1�R� +�0s�}۶e :�B�}�{P��� �X H ]��{�j��%�D�[%",�Bgl.3K��Z�.""�Z�b*��穪 ���3� bI1��+3����D��*� f���`��d �DD �}ߵ��CHfFm �̄ ��wl�}�P��{�e�w<���Yk���L�)���

d���\�E*ڽ K�ME �~{{ �뾶��V�IDr-cwD��L)�� QX��RJ�y�0 ��

��{'a���������B�� ��3̾S'�+� ������1L\��qܹ���9���z����߽� � :�� �� !�뺘u���

��� B�.�ί����z��+�a� ��� �� +���a7���!~�}�$�� ,�V�Y ���֘u��jf~�^��@ڲ���8� cr���;� ��㱿^ ˰�f�z^ooo.�k�d�p�

12-10 10:23:40.251 29017-29188/com.kinvey.sample.statusshare D/HttpTransport: -------------- RESPONSE --------------

200 OK

Content-Length: 0

Content-Type: text/html; charset=UTF-8

Date: Thu, 10 Dec 2015 12:23:40 GMT

ETag: "815cfe535e9b04747185f4d20d6d4c6e"

Server: UploadServer

Vary: Origin

X-Android-Received-Millis: 1449750220246

X-Android-Response-Source: NETWORK 200

X-Android-Sent-Millis: 1449750210218

x-goog-generation: 1449750219963000

x-goog-hash: crc32c=uwdc6A==

x-goog-hash: md5=gVz+U16bBHRxhfTSDW1Mbg==

x-goog-metageneration: 1

x-goog-stored-content-encoding: identity

x-goog-stored-content-length: 2464470

X-GUploader-UploadID: AEnB2UojFCeWLMV3G95c2aH3eSBG5lOnSdToS4_mII52zHPAkiklI9eoSz0iCzs1DbMWcA5iN4yXrG4CR9aLjY532fgDIrfbPg

12-10 10:23:40.261 29017-29017/com.kinvey.sample.statusshare D/Kinvey - Client: failed to upload linked app data

12-10 10:23:40.261 29017-29017/com.kinvey.sample.statusshare W/System.err: com.kinvey.java.KinveyException:

12-10 10:23:40.261 29017-29017/com.kinvey.sample.statusshare W/System.err: REASON: Unable to parse the JSON in the response

12-10 10:23:40.261 29017-29017/com.kinvey.sample.statusshare W/System.err: FIX: examine BL or DLC to ensure data format is correct. If the exception is caused by `key <somkey>`, then <somekey> might be a different type than is expected (int instead of of string)

12-10 10:23:40.261 29017-29017/com.kinvey.sample.statusshare W/System.err: EXPLANATION: java.lang.IllegalArgumentException: no JSON input found

12-10 10:23:40.261 29017-29017/com.kinvey.sample.statusshare W/System.err: at com.kinvey.java.core.AbstractKinveyClientRequest.execute(AbstractKinveyClientRequest.java:480)

12-10 10:23:40.261 29017-29017/com.kinvey.sample.statusshare W/System.err: at com.kinvey.java.LinkedResources.SaveLinkedResourceClientRequest.execute(SaveLinkedResourceClientRequest.java:145)

12-10 10:23:40.261 29017-29017/com.kinvey.sample.statusshare W/System.err: at com.kinvey.android.AsyncLinkedData$Save.executeAsync(AsyncLinkedData.java:221)

12-10 10:23:40.261 29017-29017/com.kinvey.sample.statusshare W/System.err: at com.kinvey.android.AsyncLinkedData$Save.executeAsync(AsyncLinkedData.java:206)

12-10 10:23:40.261 29017-29017/com.kinvey.sample.statusshare W/System.err: at com.kinvey.android.AsyncClientRequest.doInBackground(AsyncClientRequest.java:71)

12-10 10:23:40.266 29017-29017/com.kinvey.sample.statusshare W/System.err: at android.os.AsyncTask$2.call(AsyncTask.java:288)

12-10 10:23:40.266 29017-29017/com.kinvey.sample.statusshare W/System.err: at java.util.concurrent.FutureTask.run(FutureTask.java:237)

12-10 10:23:40.266 29017-29017/com.kinvey.sample.statusshare W/System.err: at com.kinvey.android.AsyncClientRequest$KinveySerialExecutor$1.run(AsyncClientRequest.java:145)

12-10 10:23:40.266 29017-29017/com.kinvey.sample.statusshare W/System.err: at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)

12-10 10:23:40.266 29017-29017/com.kinvey.sample.statusshare W/System.err: at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)

12-10 10:23:40.266 29017-29017/com.kinvey.sample.statusshare W/System.err: at java.lang.Thread.run(Thread.java:818)



What might be happening?


Hello,

I had the same problem in my project. So I said this issue in StatusShare project upgrading kinvey version that was running (2.9.5) for the version (2.10.3). Only by changing the version the app stopped to save data.


1)  Entity

package com.kinvey.sample.statusshare.model;

import java.text.ParsePosition;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.Locale;

import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.util.Log;

import com.google.api.client.util.Key;
import com.kinvey.android.Client;
import com.kinvey.java.User;
import com.kinvey.java.LinkedResources.LinkedGenericJson;
import com.kinvey.java.model.KinveyMetaData;
import com.kinvey.java.model.KinveyReference;
import com.kinvey.sample.statusshare.MainActivity;


/**
* This class maintains a Status Update which can be persisted with Kinvey.
*
* @author edwardf
* @since 2.0
*/
public class UpdateEntity extends LinkedGenericJson {


//----persisted fields
@Key("_id")
private String id;
@Key("text")
private String text;
@Key(KinveyMetaData.JSON_FIELD_NAME)
private KinveyMetaData meta;
@Key("_acl")
private KinveyMetaData.AccessControlList acl;
@Key("author")
private KinveyReference author;
@Key("comments")
private ArrayList<KinveyReference> comments;


public static final int MAX_W = 512;
public static final int MAX_H = 512;
public static final String attachmentName = "attachment";

//-----displayed inferred fields
private String authorName;
private String authorID;
private String since;
private Bitmap thumbnail;




public UpdateEntity(){
putFile(attachmentName);
}


public UpdateEntity(String userid) {
id = null;
text = null;
meta = new KinveyMetaData();
acl = new KinveyMetaData.AccessControlList();
putFile(attachmentName);
author = new KinveyReference();
author.setCollection(User.USER_COLLECTION_NAME);
author.setId(userid);


}

public void setAuthor(KinveyReference author){
this.author = author;
}

public KinveyReference getAuthor(){
return this.author;

}


public String getId() {
return id;
}

public void setId(String id) {
this.id = id;
}

public String getText() {
return text;
}

public void setText(String text) {
this.text = text;
}

public KinveyMetaData.AccessControlList getAcl() {
return acl;
}

public void setAcl(KinveyMetaData.AccessControlList acl) {
this.acl = acl;
}

public KinveyMetaData getMeta() {
return meta;
}

public void setMeta(KinveyMetaData meta) {
this.meta = meta;



}


public String getAuthorID(){
if (this.author != null && this.author.getResolvedObject() != null){
this.authorID = (String) (this.author.getResolvedObject()).get("_id");
}
return ((this.authorID == null) ? "" : this.authorID);
}

public String getAuthorName() {
if (this.author != null && this.author.getResolvedObject() != null){
this.authorName = (String) (this.author.getResolvedObject()).get("username");
}
return ((this.authorName == null) ? "--" : this.authorName);
}

public String getSince() {


ParsePosition pp = new ParsePosition(0);
Date date = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS", Locale.US).parse(this.meta.getEntityCreationTime(), pp);
since = MainActivity.getSince(date, Calendar.getInstance());

Log.i(Client.TAG, "getting since -> " + (since != null));
return since;
}



/**
* Get the thumbnail from the LinkedResource
*
* Note it closes the output stream.
*
* @return null or the image attachment
*/
public Bitmap getThumbnail() {
//If it hasn't been resolved...
if (thumbnail == null) {
//and there is an actual LinkedFile behind the Key
if (getFile(attachmentName) != null) {
//Then decode from the output stream and get the image.
thumbnail = BitmapFactory.decodeByteArray(getFile(attachmentName).getOutput().toByteArray(), 0, getFile(attachmentName).getOutput().toByteArray().length);
try {
//close the output stream
getFile(attachmentName).getOutput().close();
} catch (Exception e) {
}
}
}
return thumbnail;
}

public ArrayList<KinveyReference> getComments() {
return comments;
}

public void setComments(ArrayList<KinveyReference> comments) {
this.comments = comments;
}

public void addComment(CommentEntity newComment){
if (this.comments == null){
this.comments = new ArrayList<KinveyReference>();
}
KinveyReference ret = new KinveyReference(MainActivity.COL_COMMENTS, newComment.getId());
this.comments.add(ret);

}

public void resetCommentReferences(){
if (this.comments == null){
return;
}

for (KinveyReference c : comments){
c.remove("_obj");

}
}
}


2)

public void doUpdate() {
final ProgressDialog progressDialog = ProgressDialog.show(getActivity(), "",
"Posting. Please wait...", true);

byte[] byteArray = null;
if (image != null) {
ByteArrayOutputStream stream = new ByteArrayOutputStream();
image.compress(Bitmap.CompressFormat.PNG, 100, stream);
byteArray = stream.toByteArray();
try {
stream.close();
} catch (IOException e) {

}
}

getClient().enableDebugLogging();
saveUpdateAttachment(progressDialog, byteArray, getClient().user().getId() + "_attachment_" + System.currentTimeMillis() + ".png");
}


3) 

public void saveUpdateAttachment(final ProgressDialog progressDialog, byte[] bytes, String filename) {
UpdateEntity updateEntity = new UpdateEntity(getClient().user().getId());
updateEntity.setText(updateText.getText().toString());
updateEntity.getAcl().setGloballyReadable(true);

android.util.Log.d(Client.TAG, "updateEntity.getMeta().isGloballyReadable() = " + updateEntity.getAcl().isGloballyReadable());

if (bytes != null && filename != null) {
Log.i(Client.TAG, "there is an attachment!");
LinkedFile lf = new LinkedFile(filename);
lf.addExtra("_public", true);
KinveyMetaData.AccessControlList acl = new KinveyMetaData.AccessControlList();
acl.setGloballyReadable(true);
lf.addExtra("_acl", acl);
updateEntity.putFile("attachment", lf);
}
final ByteArrayInputStream bais = ((bytes == null) ? null : new ByteArrayInputStream(bytes));
if (bais != null){
updateEntity.getFile("attachment").setInput(bais);
}

getClient().enableDebugLogging();
getClient().linkedData(MainActivity.COL_UPDATES, UpdateEntity.class).save(updateEntity, new KinveyClientCallback<UpdateEntity>() {

@Override
public void onSuccess(UpdateEntity result) {
if (getActivity() == null){
return;
}
android.util.Log.d(Client.TAG, "postUpdate: SUCCESS _id = " + result.getId() + ", gr = " + result.getAcl().isGloballyReadable());
progressDialog.dismiss();

try {
bais.close();
} catch (Exception e) {
}

InputMethodManager imm = (InputMethodManager) getActivity().getSystemService(getActivity().INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(updateText.getWindowToken(), 0);

((MainActivity) getActivity()).bitmap = null;

if (getActivity() != null) {
((MainActivity)getActivity()).setShareList(null);

((MainActivity)getActivity()).replaceFragment(new ShareListFragment(), false);

// ((StatusShare)getSherlockActivity()).removeFragment(UpdateEditFragment.this);
// ((StatusShare)((StatusShare) getSherlockActivity()).removeFragment(getSherlockActivity().getSupportFragmentManager().);)
}
}

@Override
public void onFailure(Throwable e) {
getClient().disableDebugLogging();
if (getActivity() == null){
return;
}
Log.d(Client.TAG, "failed to upload linked app data");
e.printStackTrace();
progressDialog.dismiss();
}

}, null
);
// } else {
// Log.i(Client.TAG, "there is no attachment");
// }
}


Hi,


Can you try out latest Kinvey SDK for Android 2.10.4 which has fixed an issue related to file upload mimetype.


It is available for download here: http://devcenter.kinvey.com/android/downloads


Meanwhile, I will take a look at the code and see if I find anything unusual.



Regards,

Wani

Hi,


All the requests seem to successfully complete at Kinvey backend.


Can you paste relevant code here?



Regards,

Wani

Kinvey Support


Login or Signup to post a comment