I am working on deleting the file from the Amazon from sfdc.
I have written the code for it when am sending the request to Amazon It through error:-
System.HttpResponse[Status=HTTP Version not supported, StatusCode=505]
kindly help me to solve this problem
How can I overcome this error to pass correct request?
Code:
Datetime expire = system.now().addDays(1);
String dateString = expire.formatGmt('yyyy-MM-dd')+'T'+ expire.formatGmt('HH:mm:ss')+'.'+expire.formatGMT('SSS')+'Z';
String stringToSign = 'DELETE\n' +
'\n' +
'\n' +
dateString + '\n' +
('https://s3.amazonaws.com/'+awsKeySet[0].Name__c+'/'+fname).replaceAll(' ', '');
stringToSign = stringToSign.replaceAll(' ', '%20');
System.debug('FINDME::stringToSign - ' + stringToSign);
Blob mac = Crypto.generateMac('HMacSHA1',Blob.valueOf(stringToSign), Blob.valueOf(+awsKeySet[0].AWS_Secret_Key__c));
stringToSign = EncodingUtil.base64Encode(mac);
//String encoded = EncodingUtil.urlEncode(stringToSign, 'UTF-8');
HttpRequest con = new HttpRequest();
con.setHeader('Authorization',+awsKeySet[0].AWS_AccessKey_Id__c+':' + stringToSign);
con.setEndPoint('https://s3.amazonaws.com/'+awsKeySet[0].Name__c+'/'+'Temporary/'+fname);
con.setHeader('Host',+awsKeySet[0].Name__c+'.s3.amazonaws.com');
//con.setHeader('Date', dateString);
con.setMethod('DELETE');
Http http = new Http();
HTTPResponse res = http.send(con);
System.debug('RES.GETBODY: ' + res.getBody() + ' RES.GETSTATUS: ' + res.getStatus() + ' CON.GETENDPT: ' + con.getEndPoint());
This kind of problem typically arises from an invalid URL in the HTTP request as can be seen in this post in Salesforce success community and this post in Salesforce StackExchange. This line here is where I would start:
con.setEndPoint('https://s3.amazonaws.com/'+awsKeySet[0].Name__c+'/'+'Temporary/'+fname);
There are references to an sobject field awsKeySet[0].Name__c and a variable fname that you resolve into your URL string.
Are you certain there are no spaces or unescaped characters in the underlying value of either of those?
Related
Many posts such as this one use the REST API of Google Street View like this:
http://maps.google.com/cbk?output=xml&ll=40.7625000,-73.9741670&dm=1
However, this API does not work sometimes.
Google Street View seems does not rely on that REST API, and it may store the depthmap in this meta-file:
https://www.google.com/maps/photometa/v1?authuser=0&hl=en&gl=us&pb=!1m4!1smaps_sv.tactile!11m2!2m1!1b1!2m2!1sen!2sus!3m3!1m2!1e2!2sG2__WfQLZTzrsr7FP1wUyQ!4m57!1e1!1e2!1e3!1e4!1e5!1e6!1e8!1e12!2m1!1e1!4m1!1i48!5m1!1e1!5m1!1e2!6m1!1e1!6m1!1e2!9m36!1m3!1e2!2b1!3e2!1m3!1e2!2b0!3e3!1m3!1e3!2b1!3e2!1m3!1e3!2b0!3e3!1m3!1e8!2b0!3e3!1m3!1e1!2b0!3e3!1m3!1e4!2b0!3e3!1m3!1e10!2b1!3e2!1m3!1e10!2b0!3e3
But I do not know how to extract depthmap from it. The method using Base64 in this post of Convert depth map (base64) of google street view to image does not work because the encoded string are very different.
Could anyone can get me some ideas? Thanks very much!
Here are some Python code lines to get the meta-file from Google Street View:
def getPanoJS_frm_lonlat(lon, lat):
url = "https://maps.googleapis.com/maps/api/js/GeoPhotoService.SingleImageSearch?pb=!1m5!1sapiv3!5sUS!11m2!1m1!1b0!2m4!1m2!3d{0:}!4d{1:}!2d50!3m10!2m2!1sen!2sGB!9m1!1e2!11m4!1m3!1e2!2b1!3e2!4m10!1e1!1e2!1e3!1e4!1e8!1e6!5m1!1e2!6m1!1e2&callback=_xdc_._v2mub5"
url = url.format(lat, lon)
return requests.get(url, proxies=None)
lon = -74.2249174
lat = 40.7040015
resp = getPanoJS_frm_lonlat(lon, lat)
line = resp.text.replace("/**/_xdc_._v2mub5 && _xdc_._v2mub5( ", "")[:-2]
# print(line)
jdata = json.loads(line)
print("This part may be the depthmap:")
print(jdata[1][5][0][5][3][2])
A part of the encoded depthmap in the metafile(not quite sure, and the entire string is too long to post here, please using the code above the download the meta-file):
Q0RrQUFBSUFBUWdCQVFFQkFRRUJBUUVCQVFFQkFRRUJBUUVCQVFFQkFRRUJBUUVCQVFFQkFRRUJBUUVCQVFFQkFRRUJBUUR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FBQUFBQUlBaWVzbTlzWFVnd1M3QzBUeXpzeHRCa0FHaE84WThtRUVxaENTX0lCRDN3Y1RYV3I3UkthTEJuZElYd0h0MkpzSmVZd0ZBZjM5Q3dzZjhjc0F2dGt2Q2VzV3d2X1dkY01JOTNRVEJsVGxBd2lKNlJzTEk4empDZVpKdHdvcXNPTUtvOXV6QnJzVTV3cDZNaXNMVDR6akNramtmd2h0U09jTFZaR2pDeUJBalF0cUZKOFBhS3pyQ01TM0N3dHp5SlVMUjF0WENmdklsUWl4WE1jT3I4ampDUGVjVXd1djJIMExfMk11OXJYN2dRUXJ6UHNKT2pBRkRES0dUdjRLdm0wTElEWnFfZG5HR1FnbGM1OEgwRUI1Q1BHU2V3WU1aSFVLV0xxSEI0eWdJd3lPakZjTEIwUUZEa2xGZHYzY1ZzRUl1RmtlX1RLRmhRc21tenJ3QjZUUkQxNThDdjdXZ3cwSkc5NEUtZXhUb1F1c1QzVUdUYmdKRGtlMzJRV2gtSDBJUjc2VkJUOFVlUWg3RkZFS3ViUUpERFlzalFvYzJJRUpTUTB0Q1RCd2dRbEhJY2tMV3RSOUNNVktiUVRGcVBNS1dIZVpCb2ZZOXdpQmFRRUowNTBIQ0Jud1pRcDV6UU1MNml0Q18wWWFjd3V6RG5FSTNFd25EZUNZc1FlODhQTUl1dThDX2tFLUt3dTF4RDhETVBzUEM0aGhCd241Z0lrSThfSG9fOTRRMFFwOExKa0ZoZUI1QzE3OTN3T3VORkVMSEQ1akJRZnM2d2c=
I recently came across this problem too and I decided to dig into it with the help of a friend.
I found the GSVPanoDepth.js library that hadn't been updated in a while but still had the fundamentals of decoding the data and parsing it. It was all pretty much the same except the url has changed and the structure of the data a bit too. I forked the repo and updated it to work with the new url and structure - https://github.com/sidequestlegend/GSVPanoDepth.js
// This url no longer works
// url = "http://maps.google.com/cbk?output=json&cb_client=maps_sv&v=4&dm=1&pm=1&ph=1&hl=en&panoid=" + panoId;
url = "https://www.google.com/maps/photometa/v1?authuser=0&hl=en&gl=uk&pb=!1m4!1smaps_sv.tactile!11m2!2m1!1b1!2m2!1sen!2suk!3m3!1m2!1e2!2s" +
panoId +
"!4m57!1e1!1e2!1e3!1e4!1e5!1e6!1e8!1e12!2m1!1e1!4m1!1i48!5m1!1e1!5m1!1e2!6m1!1e1!6m1!1e2!9m36!1m3!1e2!2b1!3e2!1m3!1e2!2b0!3e3!1m3!1e3!2b1!3e2!1m3!1e3!2b0!3e3!1m3!1e8!2b0!3e3!1m3!1e1!2b0!3e3!1m3!1e4!2b0!3e3!1m3!1e10!2b1!3e2!1m3!1e10!2b0!3e3"
fetch(url)
.then(res=>res.text())
.then(res=>JSON.parse(res.substr(4)))
.then(res=>res[1][0][5][0][5][1][2])
.then(res=>{
console.log(res);
return res;
})
.then(dm => {
var decoded, depthMap;
try {
decoded = self.decode(dm);
depthMap = self.parse(decoded);
} catch(e) {
console.error("Error loading depth map for pano " + panoId + "\n" + e.message + "\nAt " + e.filename + "(" + e.lineNumber + ")");
depthMap = self.createEmptyDepthMap();
}
if(self.onDepthLoad) {
self.depthMap = depthMap;
self.onDepthLoad();
}
})
.catch(e=>{
console.error("Request failed: " + url + "\n" + e);
var depthMap = self.createEmptyDepthMap();
if(self.onDepthLoad) {
self.depthMap = depthMap;
self.onDepthLoad();
}
});
I am using the code below for saving uploaded picture and makigna thumbnail but it saves a filename without the extension to the database, therefore, I get broken links. How can I stop a strongly typed dataset and dataadapter to stop removing the file extension? my nvarchar field has nvarchar(max) so problem is not string length.
I realized my problem was the maxsize in the dataset column, not sql statement parameter, so I fixed it. You may vote to close on this question.
hasTableAdapters.has_actorTableAdapter adp1 = new hasTableAdapters.has_actorTableAdapter();
if (Convert.ToInt16(adp1.UsernameExists(username.Text)) == 0)
{
adp1.Register(username.Text, password.Text,
ishairdresser.Checked, city.Text, address.Text);
string originalfilename = Server.MapPath(" ") + "\\pictures\\" + actorimage.PostedFile.FileName;
string originalrelative = "\\pictures\\" + actorimage.FileName;
actorimage.SaveAs(originalfilename);
string thumbfilename = Server.MapPath(" ") + "\\pictures\\t_" + actorimage.PostedFile.FileName;
string thumbrelative = "\\pictures\\t_" + actorimage.FileName;
Bitmap original = new Bitmap(originalfilename);
Bitmap thumb=(Bitmap)original.GetThumbnailImage(100, 100,
new System.Drawing.Image.GetThumbnailImageAbort(ThumbnailCallback),
IntPtr.Zero);
thumb=(Bitmap)original.Clone(
new Rectangle(new Point(original.Width/2,original.Height/2), new Size(100,100)),
System.Drawing.Imaging.PixelFormat.DontCare);
/*
bmpImage.Clone(cropArea,bmpImage.PixelFormat);
*/
thumb.Save(thumbfilename);
adp1.UpdatePicture(originalrelative, thumbrelative, username.Text);
LoginActor();
Response.Redirect("Default.aspx");
}
}
Looks like the problem is you are using HttpPostedFile.FileName property, which returns fully-qualified file name on the client. So, this code string originalfilename = Server.MapPath(" ") + "\\pictures\\" + actorimage.PostedFile.FileName; generates something like this:
c:\inetpub\pictures\c:\Users\Username\Pictures\image1.jpg
Use FileUpload.FileName property everywhere and you will probably get what you want.
Use this to get Image or file extension :
string Extension = System.IO.Path.GetExtension(FileUpload.FileName);
how can I get only the domain, for example:
The url: http://localhost:11093/SiteA/Admin/Default.aspx
Then, I want to get only the: http://localhost:11093/SiteA/
I am using:
Path.GetFileName(Request.Url.Host)
But only get the: localhost, and trying:
Path.GetFileName(Request.Url.PathAndQuery)
But get the whole address. Thank you very much.
Try this one:
var HostAndPath = Request.Url.AbsoluteUri.Replace(Request.Uri.AbsolutePath, "")
Try something like this
Uri uri = new Uri("http://localhost:11093/SiteA/Admin/Default.aspx");
string requested = uri.Scheme + uri.SchemeDelimiter + uri.Host + ":" + uri.Port;
You can work directly on the request URI
Uri uri = Request.Url;
string requested = uri.Scheme + uri.SchemeDelimiter + uri.Host + ":" + uri.Port;
Try this...
Page.ResolveUrl("~").ToString()
I'm trying to post an action to open graph but the only response I'm getting is "false".
According to the "Creating and Using Actions" portion of the API it appears that I'm doing this correctly.
Code sample below.
var url = facebook.root + 'objects/' + verb + '/' + noun + '.html';
var method = 'https://graph.facebook.com/me/joe_longstreet:' + verb + '?' + noun + '=' + url + '&distance=' + distance + '&tags=' + users + '&access_token=' + facebook.token;
FB.api(method, 'post', function(response){
if(response.error){
alert(response.error.message);
} else{
console.log(response);
var message = 'Posted to your timeline!';
alert(message);
}
});
Where verb = run, noun = route, and url = my objects page.
Specifically:
https://graph.facebook.com/me/joe_longstreet:run?route=http://joelongstreet.showoff.io/Facebook_app/objects/run/route.html&distance=&tags=1915805&access_token=ABCDE
Fake access token above. What am I doing wrong here?
Looks like you don't need to include the graph.facebook.com portion of the url. so it should just read /me/joe_longstreet:run?...
I'm trying to write a little flex app that has a paint/canvas type feature to draw an image, which I then want to post to a rails server side. I'm following the post here, but can't get as far as he did due to the following error:
NoMethodError (undefined method `rewind' for #):
I googled that and found this which says the problem is due to an empty filename, but I thought I had that from the example. However, I altered the example to simplify the post by reducing the form parameters, but I could have easily messed something up since I really don't know what I'm doing with this multipart form content.
I was hoping to at least log the request params, but unfortunately I can't, since it's failing before being routed and due to my inexperience with rails. I'll ask that in a separate question and hopefully be able to edit this question with the request params.
Here's my code:
public static function sendPic(simplePaint : SimplePaint) : void {
var jpgSource:BitmapData = new BitmapData (simplePaint.width, simplePaint.height);
jpgSource.draw(simplePaint);
var jpgEncoder:JPEGEncoder = new JPEGEncoder(85);
var ba:ByteArray = jpgEncoder.encode(jpgSource);
var request:URLRequest = new URLRequest("../drawings");
request.method = URLRequestMethod.POST;
var boundary : String = "----------Ij5GI3GI3ei4GI3ei4KM7GI3KM7KM7";
request.contentType = "multipart/form-data; boundary=" + boundary;
request.data = getMultiPartRequestData(boundary, 'drawing', 'mypic.jpg', ba);
var urlLoader:URLLoader = new URLLoader();
urlLoader.dataFormat = URLLoaderDataFormat.BINARY;
urlLoader.load(request);
}
private static function getMultiPartRequestData(boundary:String,
resourceName:String,
filename:String,
bytes:ByteArray):ByteArray {
//Alert.show("haha");
var lf:String = "\r\n";
var part1:String = '--' + boundary + lf +
'Content-Disposition: form-data; name="Filename"' + lf + lf +
'{0}' + lf +
'--' + boundary + lf ;
part1 += 'Content-Disposition: form-data; name="commit"' + lf + lf +
'Create' + lf +
'--' + boundary + lf +
'Content-Disposition: form-data; name="{1}[pic] ";' +
'filename="{0}"' + lf +
'Content-Type: application/octet-stream' + lf + lf
var part2:String = '--' + boundary + lf +
'Content-Disposition: form-data; name="Upload"' + lf + lf +
'Submit Query' + lf +
'--' + boundary + '--'
var result:ByteArray = new ByteArray();
// Filling in the parameters as per comment above
result.writeMultiByte(StringUtil.substitute(part1,
filename,
resourceName), "ascii");
result.writeBytes(bytes,0,bytes.length);
result.writeMultiByte(part2, "ascii");
return result;
}
The answer was in the answer of the earlier linked question. I had just missed it, or undid it, in my copy-paste-edit of that answer.
The code that needs to change is this part :
'Content-Disposition: form-data; name="{1}[pic] ";' +
'filename="{0}"' + lf +
'Content-Type: application/octet-stream' + lf + lf
it needs to be changed to:
'Content-Disposition: form-data; name="{1}[pic]"; ' + // space moved here
'filename="{0}"' + lf +
'Content-Type: application/octet-stream' + lf + lf
When you move the space to after the semicolon, it works.