Could you please provide a little more information on your requirement. Based on my understanding, if you want to add image to User/Contact you can add a Text (Rich Text) field and add images to it. This field will look for image located in your machine.
User userObject = [select id,Email,FirstName,FullPhotoUrl,LastName,Name,SmallPhotoUrl,companyName,Title,Username,UserType from User where Id =:UserId];
I want to get SmallPhotoUrl or FullPhotoUrl value as blob so that I could insert this image as attachment where ever I want . But it only retrun the photoUrl not like a download url .
// this is the controller for uploading the image
public class attachmentsample {
public Contact cont;
public attachmentsample(ApexPages.StandardController controller) {
// this.cont = (Contact)controller.getRecord();
}
Public Attachment myfile;
Public Attachment getmyfile()
{
myfile = new Attachment();
return myfile;
}
Public Pagereference Savedoc()
{
String Contactid = System.currentPagereference().getParameters().get('id');
Attachment a = new Attachment(parentId = Contactid, name=myfile.name, body = myfile.body);
/* insert the attachment */
insert a;
// cont.ImageId__c = a.id;
// update cont;
return null;
}
}
I have smallimage url field sting value getting from User object query . if you copy and paste that url in salesforce url instance then user pic is visible that pic I want to get first in blob type and then I want insert that image in any object the object attachment list .
//If you want to get a PDF file the Content Type would be'application/pdf'
req.setHeader('Content-Type', 'image/jpeg');
req.setCompressed(true);
req.setTimeout(60000);
HttpResponse res = null;
res = h.send(req);
//These next three lines can show you the actual response for dealing with error situations
string responseValue ='';
responseValue = res.getBody();
system.debug('Response Body for File: ' + responseValue);
//This is the line that does the magic. We can get the blob of our file. This getBodyAsBlob method was added in the Spring 2012 release and version 24 of the API.
Hi,
Could you please provide a little more information on your requirement. Based on my understanding, if you want to add image to User/Contact you can add a Text (Rich Text) field and add images to it. This field will look for image located in your machine.
Thanks,
Aravind.
User userObject = [select id,Email,FirstName,FullPhotoUrl,LastName,Name,SmallPhotoUrl,companyName,Title,Username,UserType from User where Id =:UserId];
I want to get SmallPhotoUrl or FullPhotoUrl value as blob so that I could insert this image as attachment where ever I want . But it only retrun the photoUrl not like a download url .
Hope you understand !
Hello there if you looking for a custom button to upload pic on the record, then here a sample i found few days back!!
Hope it helps!!
Thanks but that is not my solution ...
I have smallimage url field sting value getting from User object query . if you copy and paste that url in salesforce url instance then user pic is visible that pic I want to get first in blob type and then I want insert that image in any object the object attachment list .
I found this if it helps,
Http h = new Http();
Reference: http://www.sundoginteractive.com/sunblog/posts/saving-the-contents-of-an-image-or-file-url-and-saving-to-an-attachment-or