Parse Android fails to download image with a moved permanently error - android

I am getting the following exception when trying to download a ParseFile using getData() method.
com.parse.ParseException: Download from S3 failed. Moved Permanently
at com.parse.ParseAWSRequest.onResponseAsync(ParseAWSRequest.java:43)
at com.parse.ParseRequest$3.then(ParseRequest.java:137)
at com.parse.ParseRequest$3.then(ParseRequest.java:133)
at bolts.Task$15.run(Task.java:917)
at bolts.BoltsExecutors$ImmediateExecutor.execute(BoltsExecutors.java:105)
at bolts.Task.completeAfterTask(Task.java:908)
at bolts.Task.continueWithTask(Task.java:715)
at bolts.Task.continueWithTask(Task.java:726)
at bolts.Task$13.then(Task.java:818)
at bolts.Task$13.then(Task.java:806)
at bolts.Task$15.run(Task.java:917)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1113)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:588)
at java.lang.Thread.run(Thread.java:818)
The ParseFile is a jpg which is uploaded and then put into a ParseObject called ImageObject. The ImageObject has several other parameters like caption, width, height which upload and download correctly. The image itself uploads correctly as confirmed through the dashboard. Only during the download I get the above exception.
This is my upload code
file.saveInBackground(new SaveCallback() {
#Override
public void done(ParseException e) {
if (e == null) {
Log.d(tag, "Successfully uploaded image file");
ParseObject image = new ParseObject("imageObject"); //Create new Image-ParseObject and set values
image.put("author", ParseUser.getCurrentUser());
image.put("imageFile", file);
image.put("caption", caption);
image.saveInBackground(new SaveCallback() {
#Override
public void done(ParseException e) {
if(e==null){
Log.d(tag, "Successfully saved image file to object");
}else{
Log.d(tag, "Failed to save image file to object", e);
}
}
});
} else {
Log.d(tag, "Failed to save image", e);
}
}
my download code is pretty much ParseFile.getFile() after I have retrieved all the ImageObjects through a ParseQuery.
I Followed Line 43 of ParseAWSRequest.java and I found this,
if (statusCode >= 200 && statusCode < 300 || statusCode == 304) {
// OK
} else {
String action = method == ParseHttpRequest.Method.GET ? "Download from" : "Upload to";
return Task.forError(new ParseException(ParseException.CONNECTION_FAILED, String.format(
"%s S3 failed. %s", action, response.getReasonPhrase())));
}
This and the "Permanently removed" points to my nginx reverse proxy, which returns a 301 code in the redirect to https. Unfortunately I am not sure where to proceed from here.
Extra information,
I have blocked port 80(http) in the firewall for a test and it seems that for the download parse-android-sdk is trying to download from http. Which is odd because I have specified my parse-server link with "https", and the fact that upload is working fine. I can see the uploaded image using dashboard on my server.
Using,
Parse Server 2.2.13
Parse Android SDK 1.13.1
Parse Dashboard 1.0.14

I found a workaround to this issue just by directly downloading the file. I used ParseFile.getUrl() method to get the url and then use that to download and use the file.
In my case it was .jpg files. And then I used an external library that takes care of all the downloading/caching/loading into imageviews.
Both of these libraries work well
https://github.com/koush/ion
http://square.github.io/picasso/

Related

Android ONVIF - Internal Server Error when trying to retrieve profiles from ONVIF IP camera

I'm currently building an Android Things application that communicates with an ONVIF IP camera following this youtube tutorial I can talk to the camera and I can get services and device information but when I try to retrieve profiles, it responds with D/RESPONSE: Response{protocol=http/1.1, code=500, message=Internal Server Error
What would cause this response?
onCreate
currentDevice = OnvifDevice("192.168.1.5","admin","password")
currentDevice.listener = this
currentDevice.getServices()
Log.d("REQUEST", "Get services");
requestPerformed
override fun requestPerformed(response: OnvifResponse) {
//method called when response is received from camera
Log.d("RESPONSE", response.parsingUIMessage);
if (response.request.type == OnvifRequest.Type.GetServices) {
Log.d("REQUEST", "Get device information");
currentDevice.getDeviceInformation()
}
else if (response.request.type == OnvifRequest.Type.GetDeviceInformation) {
Log.d("REQUEST", "Get profiles");
currentDevice.getProfiles()
}
else if (response.request.type == OnvifRequest.Type.GetProfiles) {
Log.d("REQUEST", "Get stream URI");
currentDevice.mediaProfiles.firstOrNull()?.let {
currentDevice.getStreamURI(it)
}
}
else if (response.request.type == OnvifRequest.Type.GetStreamURI) {
Log.d("REQUEST", "Get get video stream");
currentDevice.rtspURI?.let { uri ->
val surfaceView = findViewById<SurfaceView>(R.id.surfaceView)
vlcVideoLibrary = VlcVideoLibrary(this, this, surfaceView)
vlcVideoLibrary?.play(uri)
}
}
}
Sometimes, the problem isn't with the code you wrote, but with the device/camera you're using... I had a problem with one of my camera... It wasn't returning a valid response when asked for its status. here
I would suggest you to look for any camera software update. If this still doesn't work, I would suggest to try with another device as #sasikumar said.

Android: Parse Server save Error 111: This is an invalid Polygon

I'm trying to save a GeoPolygon into my Parse server using an android app but I keep getting an:
error 111: this is not a valid polygon
this is my code:
//create the parse object
ParseObject obj = new ParseObject("SomeClass");
List<ParseGeoPoint> geoPoints = new ArrayList<ParseGeoPoint>();
geoPoints.add(new ParseGeoPoint(1.468074, 110.429638));
geoPoints.add(new ParseGeoPoint(1.468075, 110.429287));
geoPoints.add(new ParseGeoPoint(1.467376, 110.429681));
geoPoints.add(new ParseGeoPoint(1.467373, 110.429283));
ParsePolygon geoPolygon = new ParsePolygon(geoPoints);
obj.put("Boundaries", geoPolygon);
obj.saveInBackground(new SaveCallback() {
#Override
public void done(ParseException e) {
if (e == null) {
Toast.makeText(getContext(), "Geo Polygon save complete.", Toast.LENGTH_SHORT).show();
} else {
Toast.makeText(getContext(), "Geo Polygon save failed. error: " + e.getMessage(), Toast.LENGTH_SHORT).show();
}
}
});
I followed the Docs for geopolygons here:
http://docs.parseplatform.org/android/guide/#parsepolygon
and somehow, even when I copy pasted the code provided in the docs, it doesnt work.
Any suggestions/ solutions are most welcomed.
I believe not many people may see this but I'll post my solution to this anyway.
The issue was solved after I updated the version of my Parse Server. I didn't note which version I updated the Parse Server from but my current Parse Server is now v2.7.1 .
Previous/ older version of Parse Server does not support geo-Polygons.

How to receive file on Spring server send from a client using retrofit2

I am currently trying to upload a file from an android client using retrofit2 to a server using Spring Boot and its REST api.
CLIENT
I specifiy the upload method as described here: https://github.com/square/retrofit/issues/1063
public interface RetroRespondService {
#Multipart
#POST("/v1/answers")
public Call<ResponseDTO> sendPictures(#Part("file\"; filename=\"image.png")RequestBody image);
}
In another class the method to provide the actual image is declared:
(Now its just a test scenario. When image uploading is actually accomplished it will get more sophisticated.)
public void performAnswerRequest() {
try {
if (mRetrofit == null) {
mRetrofit = new Retrofit.Builder()
.baseUrl(DataHolder.getHostName())
.build();
}
//load test image
AssetManager manager = getAssets();
File file = new File(getFilesDir(), "image.png");
Utility.writeBytesToFile(new BufferedInputStream(manager.open("heart.png")), file);
RetroRespondService requestService = mRetrofit.create(RetroRespondService.class);
RequestBody image= RequestBody.create(MediaType.parse("multipart/form-data"), file);
Call<ResponseDTO> response = requestService.sendPictures(image);
response.enqueue(new AsyncAnswerResponse());
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
SERVER
What I actually do not know is, how to properly get the image on the spring side.
#RequestMapping(value = API_VERSION + "/answers", method = RequestMethod.POST)
#ResponseBody
ResponseEntity<ResponseDTO> addAnswers(#RequestParam("file\"; filename=\"image.png") MultipartFile answers) throws DBEntryDoesNotExistException, EvaluationException, ParticipantException {
// In fact I have set a brake point here. Never entered the method yet, though
System.out.println("Yay!")
return null;
}
ERROR
Request: localhost:8080/v1/answers raised org.springframework.web.bind.MissingServletRequestParameterException:
Required MultipartFile parameter 'file"; filename="image.png' is not present
Since wireshark reports that in fact a request of size 1894 Bytes was send and this is the size of the image i want to upload I strongly believe the the data is actually transmitted but cannot be decoded from the server.
I have also seen this answers: How to config "CommonsMultipartResolver" in spring4 without xml to upload file
and subsequently implemented this class on the server side:
#Configuration
public class MultipartConfiguration {
#Bean
public CommonsMultipartResolver multipartResolver() {
CommonsMultipartResolver resolver=new CommonsMultipartResolver();
resolver.setDefaultEncoding("utf-8");
resolver.setMaxUploadSize(1048576);
return resolver;
}
}
If you have any pointers in how to solve this I would appreciate your answer tremendously :)
If there are any questions left unanswered feel free to ask away.
Btw.: Sending and receiving JSON encoded data works just fine in both directions.

How to load Facebook image url in volley

Im trying to load Facbeook url image from graph api in volley image loader.
At first there was an error response returning for me 302 and 301 for redirecting the url i check the mirror library for volley and compiled it in the gradle file but now the error response is 400 i don't know what is causing that here is my code :
enter code here
try {
URL picture = new URL("https://graph.facebook.com/v2.4/" + fb_ID + "/picture?type=large);
fb_Picture = picture.toString();
} catch (MalformedURLException e)
{
e.printStackTrace();
}
//Loading the image
ImageLoader imageLoader = AppController.getInstance().getImageLoader();
imageLoader.get("https://graph.facebook.com/v2.4/" + fb_ID + "/picture?type=large", new ImageLoader.ImageListener() {
#Override
public void onErrorResponse(VolleyError error) {
Log.e("ResponseImage", "Image Load Error: " + error.getMessage());
}
#Override
public void onResponse(ImageLoader.ImageContainer response, boolean arg1) {
if (response.getBitmap() != null) {
// load image into imageview
userImage.setOval(true);
userImage.setScaleType(ImageView.ScaleType.CENTER_CROP);
userImage.setImageBitmap(response.getBitmap());
}
}
});
how can i get the actual url image without this url or how can i load this url in volley any help would be appreciated thank you.
If you are doing this in an app, you will need to use an access token to GET https://graph.facebook.com/v2.4/<FBID>/picture?type=large. This will return a JSON object similar to this one:
{
"data": {
"is_silhouette": false,
"url": "https://fb.com/..."
}
}
After parsing, this JSON object's data.url member can be used to create image view objects in your app. You can read the full documentation on this Graph API edge here. You can read more about Using Graph API in general here.
If you are just loading a single profile image uri provided from facebook sdk, you can simply use Asynctask and call BitmapFactory.decodeStream to download the image into an Imageview. The problem with volley is it doesn't handles https images automatically due to shared security reasons and you have to manually create a custom volley Requestque with HurlStack and SSL in order to display the images.

Unable to upload a media file on S3 servers from Android using Retrofit

I am using Retrofit library to upload media files (multipart) from my Android application. The servers are on Amazon using S3.
I am getting this following error :
05-15 20:17:38.515: W/System.err(649): Caused by: javax.net.ssl.SSLException: Write error: ssl=0x5eed7ca0: I/O error during system call, Broken pipe
Few points :
1. I have tested the API using POSTMAN and it is working perfectly. (no issues with max upload size as well.)
2. Weirdly this is running(uploading) successfully in one of my phones ie Moto E. The phone it is not working includes Moto G2 and Xperia SP as of now.
3. I am able to make normal requests through Retrofit successfully. Its uploading media files that is an issue.
Here is the code to upload :
#Multipart
#POST("/journeys/{journey_id}/videos")
public void uploadVideo(
#Path("journey_id") String journeyId,
#Part("api_key") TypedString apiKey,
#Part("video[user_id]") TypedString userId,
#Part("video[video_file]") TypedFile video,
Callback<String> callback);
public static void uploadVideo(final Context context, final Video video) {
RestAdapter restAdapter = new RestAdapter.Builder().setConverter(new StringConverter())
.setEndpoint(Constants.TRAVELJAR_API_BASE_URL).build();
TravelJarServices myService = restAdapter.create(TravelJarServices.class);
myService.uploadVideo(TJPreferences.getActiveJourneyId(context), new TypedString(
TJPreferences.getApiKey(context)),
new TypedString(TJPreferences.getUserId(context)), new TypedFile("video/*",
new File(video.getDataLocalURL())), new Callback<String>() {
#Override
public void success(String str, retrofit.client.Response response) {
try {
Log.d(TAG, "video uploaded successfully " + str);
} catch (JSONException e) {
e.printStackTrace();
}
}
#Override
public void failure(RetrofitError retrofitError) {
Log.d(TAG, "error in uploading video" + retrofitError);
retrofitError.printStackTrace();
}
});
}
I have been researching on this issue for a while now and cannot come to a solution. I don't want to switch to another library as this should work for me as well. Any help will be highly appreciated. TIA

Categories

Resources