I want to upload a picture from phone (android) to a server (Editing avatar of a profile).
To select the picture i am using react-native-image-picker.
This is my API-Call
request
.post(apiurl)
.set("auth", token)
.attach('avatar', avatar)
.end(async function (err,res) {
if(res.status === 200) {
console.log("Update views...");
}
});
As far as is read and understood the docs, i just need to pass the filepath to the .attach function.
So mine looks like this (android):
avatar = file:///storage/emulated/0/path/on/phone/new_avatar.jpg
I get the path from the react-native-image-picker and add the file:// at the beginning.
But what am I missing?
In the server logs we can see that it returns 500. In our API-Test class, at least as far as we tested it, it only returns 500, when it couldnĀ“t find the file, e.g. a wrong path was passed as an argument.
Cheers and thanks in advance!
Related
Alright, here goes. I'm dealing with an ionic project. In this specific scenario we're dealing with testing the Android version of the app. I can get images from the file system just fine, they come back in the form of a string url that looks something like this,
content://com.android.providers.media.documents/document/image%3A5744
The processor that is then supposed to blob the file and pass it up the line looks like this:
return this.file.readAsArrayBuffer(urlData.url, urlData.fileName)
.then((item) => {
return new Blob([new Uint8Array(item)]);
})
.catch((err) => {
console.log(err.message)
}).then((res)=>{
return new Blob([res])
})
But then I get the error SECURITY_ERR, which the documentation doesn't really talk about.
This works just fine for the pictures I take with the camera, which all have urls that look like this
file:///storage/emulated/0/Android/data/<appname>/cache/1502211622334.jpg
The issue is, as far as i can find, there is no documentation on what causes this error. I have no idea what to change to make my code work. I have verified the URI is valid, using the checkFile method.
So it turns out you can't use content urls with file.readAsArrayBuffer instead you have to first resolve the url into something readAsArrayBuffer can understand. To do this, i used the ionic native filePath plugin.
Once it was installed and included in the page where I needed it, I used the
filePath.resolveNativePath(url)
method on my url, since this returns a promise, I chained my readAsArrayBuffer onto a then statement prepended to it. I did have to use an if statement to have branching paths for content urls (Which required resolveNativePath) and non-content urls which were already working.
This solution works as far as I can tell.
I am trying to get the image URL from the Dropbox and I followed the below code from the documentation.
try {
Entry directory = dropboxApi.metadata("/", 1000, null, true, null);
directory.mimeType = "image*//*";
for (Entry entry : directory.contents) {
DropboxAPI.DropboxLink link = dropboxApi.media(entry.path, false);
if (link.url.contains(".jpeg") || link.url.contains(".png") || link.url.contains(".jpg"))
files.add(link.url);
}
} catch (DropboxException e) {
e.printStackTrace();
}
Based on this code I can get the image URL. But it is not working after hours.
In my scenario, I want to get the image URL and I will send it to server API. So when I retrieve other API, I will get the image URL, what I sent. Once I got the URL, just I want to set it to imageview.
I have verified this link. I got the different link by using share method. But I don't know how to set that into my ImageView, whereas by using media method I can get the URL and I can set it to ImageView.
Please can someone help me to solve this problem
If i make an Http request for share url then I am getting image name with download option.
I am getting 16 headers.
From this am not getting any clue. There is no header name contains Location.There is one content-piracy-policy which gives some url values combined. But it is also not relevant.
What I have
I have an image File object trying to post to Tumblr using Jumblr API
My problem
When I try to post the image I get com.tumblr.jumblr.exceptions.JumblrException: Bad Request Response code :400
My code
client = new JumblrClient(CONSUMER_KEY,SECRET_KEY);
client.setToken(TOKEN, TOKEN_SECRET);
User user=client.user();
userName=user.getName();
PhotoPost photoPost=client.newPost(client.user().getBlogs().get(0).getName(),PhotoPost.class);
photoPost.setCaption("My Tumblr post");
photoPost.setPhoto(new Photo(Methods.FILE_IMAGE));
photoPost.save();
I've encountered the same issue using Jumblr.
Instead of this method (does it somehow trigger Android gallery? Couldn't find any javadoc for Methods.FILE_IMAGE)
photoPost.setPhoto(new Photo(Methods.FILE_IMAGE));
I suggest you to try any flavor of
photoPost.setData(new File(fileName)); //if it's possible on Android
And please try it with different files: Tumblr has not only file-size limitations, but also some weird check for file being valid. ~3% of gif files I upload throw Bad Request Response code :400. Those files are not exceeding GIF size limit and they're displayed fine on my machine, but Tumblr, for some reason rejects them, so please try post.setData and try it with some bulletproof-valid file, because from the rest of your code - it definitely looks like you're doing it right
I had a similar problem posting a video & audio. However, posting an Image worked like a charm..
JumblrClient client = new JumblrClient(
CONSUMER_KEY,
SECRET_KEY
);
client.setToken(
TOKEN,
TOKEN_SECRET
);
PhotoPost post = client.newPost(strBlogName, PhotoPost.class);
post.setCaption("This is my caption");
post.setData(new File(fileUri.getPath()));
post.save(); //Initiates upload of image file
For my app, I'm using the Cordova CameraPreview plugin, to take pictures.
Once, a picture is taken, I get a path like this (and a 2nd one for the thumbnail, but not more):
/data/data/com.foo.bar/files/filename.jpg
Including the picture via
<img src="/data/data/...">
it works fine, so the path seems to be valid.
However, if I try to delete pictures, it doesn't work.
My Code:
window.resolveLocalFileSystemURL(the_path, function (result) {
alert("I'm in");
result.remove(function(){
alert("removed image");
});
});
The I'm in alert doesn't appear, in my console (Android Studio) I get the following error:
java.net.MalformedURLException: No installed handlers for this URL
Do I have to modify the URL, or what's wrong?
I found a solution via trial and error.
prepending
file://
to the path, so that it looks like
file:///data/data/com.foo.bar/files/filename.jpg
worked for me. But I've no idea, if this works in iOS, too.
I used graph API Json Response of Facebook Wall Post Images and display in my APP i successfully got it. But the wall images look very Blur how to resolve? i used this code for get wall picture
URL url=new URL(hashMap.get("picture_url"));
bitmap=BitmapFactory.decodeStream(url.openConnection().getInputStream());
((ImageView)view.findViewById(R.id.imageView_FullImage)).setImageBitmap(bitmap)
The Facebook Graph API as well as the FQL data set always returns the Picture URL of a thumbnail. If you look at the URL it returns, it will have one of these ending (right before the image extension .jpg, .png, etc) _t., _a.. For example, if the URL is to a JPG file, it could have an ending _t.jpg
The idea is to swap the ending and choose a normal size for the image that is returned. To do this, use the code below that will replace the endings with the one for normal sized images (that should have the _n.)
By the way, I don't think the tag you are looking for is picture_url. It should be just picture. But regardless, get the source URL as shown below, replace the endings and then pass it to the this line in your code:
// THIS SHOULD BE AFTER THE if....else code block
bitmap=BitmapFactory.decodeStream(url.openConnection().getInputStream());
CODE TO REPLACE THE VARIOUS THUMBNAIL IMAGES: By the way, this is production code and works perfect.
String PICTURE_URL;
String getPicture = JOFeeds.getString("picture");
if (getPicture.contains("_t.")) {
PICTURE_URL = getPicture.replaceAll("_t.", "_n.");
} else if (getPicture.contains("_a.")) {
PICTURE_URL = getPicture.replaceAll("_a.", "_n.");
} else if (getPicture.contains("_s.")) {
PICTURE_URL = getPicture.replaceAll("_s.", "_n.");
} else if (getPicture.contains("_q.")) {
PICTURE_URL = getPicture.replaceAll("_q.", "_n.");
}
Note: However, in some cases, like a Video preview or a Link preview, it will not always have a bigger image available. Nothing much you can do about it nor can Facebook I suspect. These typically come from posts that are shared by users from other websites.