Upload Service Issue

0 votes

I am using cocos2d-js to develop my game which is not support remote loading of images over https protocol, so I developed a small custom routine to download the facebook profile pics to APP42 cloud and then download the pics remotely to the game.

To achive this I open httpconnection and get an inputStream for the picture and then use uploadService.uploadFile to upload the file to APP42, sometimes this is working fine with no issues, but sometimes it load just half of the picture.

CODE is here:

URL url;
JSONObject jsonResponse = new JSONObject();
Date d = new Date();
SimpleDateFormat df = new SimpleDateFormat("ddMMyyyy");
try {
String fileName="";
fileName = df.format(d) + "_" + userID+"_pic.jpg";
UploadService uploadService = sp.buildUploadService();
try{
 
Upload u = uploadService.getFileByName(fileName);
if (u.getFileList().size()>0){
String App42URL = u.getFileList().get(0).getUrl();
jsonResponse.put("url", App42URL);
jsonResponse.put("errorCode", "0");
return new HttpResponseObject(HTTP_STATUS_SUCCESS, jsonResponse);
}
}catch(Exception ex){
}
 
url = new URL("http://graph.facebook.com/" + userID +"/picture?type=square&width="+width+"&height="+width);
 
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setInstanceFollowRedirects(true);
HttpURLConnection.setFollowRedirects(true);
connection.setReadTimeout(0);
int status = connection.getResponseCode();
boolean redirect = false;
if (status != HttpURLConnection.HTTP_OK){
if (status == HttpURLConnection.HTTP_MOVED_TEMP
||status == HttpURLConnection.HTTP_MOVED_PERM
||status == HttpURLConnection.HTTP_SEE_OTHER)
redirect = true;
}
 
if (redirect){
String newURL = connection.getHeaderField("Location");
connection = (HttpURLConnection) new URL(newURL).openConnection();
}
InputStream is = connection.getInputStream();
 
 
UploadFileType fileType = UploadFileType.IMAGE; 
 
 
String desc = "Pic of " + userID;
Upload up = uploadService.uploadFile(fileName, is,fileType, desc);
String App42URL = up.getFileList().get(0).getUrl();
jsonResponse.put("url", App42URL);
jsonResponse.put("errorCode", "0");
return new HttpResponseObject(HTTP_STATUS_SUCCESS, jsonResponse);
 
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}catch (Exception e){
// TODO Auto-generated catch block
e.printStackTrace();
}
try {
jsonResponse.put("errorCode", "-1");
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return null;

 

asked Oct 29, 2014 in App42 Cloud API-BaaS by shadiho (10 points)

1 Answer

0 votes

Hello,

It looks very strange that your half of file is uploaded. It should be either uploaded fully or should break in between. There are scenarios while downloading the image that you can only see half of the image  specially if you are on slow network. Can you check it again on that uploaded Image and see if it renders correctly?. Also, please compare it with original image too, there might be a chance that your original image itself is half cropped.

Please send us URL of uploaded Image if above check fails.

 

Thanks,

Himanshu Sharma

answered Oct 30, 2014 by hs00105 (2,005 points)
Hello Shadiho,

I hope your query has been resolved, kindly let us know if you have more question for us.
Himanshu Sharma
Download Widgets
Welcome to ShepHertz Product line forum, where you can ask questions and receive answers from the community. You can also reach out to us on support@shephertz.com
...