ImageURL got expired after some particular time - image

I am having set of URLs which needs to converted to base64 in order to push image to Salesforce File object in WSO2 EI 6.3.0. while converting imageUrl to base64 i'm getting "expires" value too old message.
here is my code. `
<call>
<endpoint>
<http method="get" uri-template="{uri.var.url}"/>
</endpoint>
</call>
<log level="full" seperator="====Base64Content===="/>
<enrich description="EnrichFileContent">
<source clone="true" type="body"/>
<target property="image_val" type="property"/>
</enrich>
<log level="custom">
<property name="===image_val===" expression="get-property('image_val')"/>
</log>
`
I am pretty much sure that there is no issue in my code. because by using that same code , i can retrieved base64 from that same url which previously works. after some time it gets expired.
FYI,
ImageURL: https://carsales.pxcrush.net/car/dealer/y67p1dpz5f7zc3swhxi93ur9e.jpg?pxc_expires=20191203040935&pxc_clear=1&pxc_size=2500,2500&pxc_method=limit&pxc_signature=db8a850b8401d95b37fa3658a2fcbb5e
Getting base64 from ImageURL

It seems that the error message is getting printed even if you directly access the URL via browser. Isn't it?
I changed the "pxc_expires" query param to a newer one "pxc_expires=20191226040935". Now I got a different error.
Bad signature
Then I removed the "pxc_signature=db8a850b8401d95b37fa3658a2fcbb5e" altogether, then I was able to retrieve the image.
Are you sure you are accessing the image from the correct URL? I think, using the correct image URL would solve the problem.

Related

ImageResizer AzureReader2 redirectToBlobIfUnmodified not working

I am using Image Resizer's AzureReader2 and everything is working fine except when I try to get the unmodified image it redirects to my blob storage.
If i request a modified image it returns the correct url:
http://localhost:57474/azure/images/test/githubavatar.jpg?width=200&height=600
But requests for the unmodified image redirect to blob storage
http:localhost:57474/azure/images/test.jpg
but instead it is redirecting to blob storage:
https://{storageAccount}.blob.core.windows.net/images/test/test.jpg
I have redirectToBlobIfUnmodified set to false but it doesn't do anything
<resizer>
<plugins>
<add name="MvcRoutingShim" />
<add name="AzureReader2"
redirectToBlobIfUnmodified="false"
connectionString="DefaultEndpointsProtocol=https;AccountName={storageAccountName};AccountKey={storageAccountKey}"
endpoint="https://{storageAccountName}.blob.core.windows.net/"
/>
</plugins>
</resizer>
I'm not too familiar with ImageResizer AzureReader2 but I did a little research on there docs.
From what I understand, if you set the endpoint to localhost rather than blob storage, then the server should perform redirects to localhost when you don't need to modify the blob.

Complex routing WSO2 API resourse uri template

Short Version.
I am trying to create a API that will handle
/goals/risks
/goals/types
/goals/{goalID}
So far this is what I have but it isn't quite what I am looking for. as it gives me /goals/goal/{goalId}
<api xmlns="http://ws.apache.org/ns/synapse" name="GoalAPI" context="/goals">
<resource methods="GET" uri-template="/risks" faultSequence="ReturnError">...</resource>
<resource methods="GET" uri-template="/types" faultSequence="ReturnError">...</resource>
<resource methods="GET" uri-template="/goal/{goalId}" faultSequence="ReturnError">...</resource>
</api>
GoalID will always match /^\d+$/ so if I can route by that somehow it will work. eventually I will want to add /goals/{goalID}/item and /goals/{goalID}/items/{itemID} also but I believe that will be easy enough once I figure out the first step.
If there is no way to do this here, is there a way I can rewrite the url inside wso2 before it reaches the resource and I would be able to then replace /goals/(\d+.*) with /goals/goal/$1? I know I could route it though a proxy and rewrite it in apache or something but that seems to defeat WSO2's purpose to me.
So after looking into this more without success and getting no response on I just stared at the code can came up with...
<api xmlns="http://ws.apache.org/ns/synapse" name="GoalAPI" context="/goals">
<resource methods="GET" uri-template="/{goalID}" faultSequence="ReturnError">
<inSequence>
<switch source="get-property('uri.var.goalId')">
<case regex="risks">...</case>
<case regex="types">...</case>
<default>...Handle the ID here...</default>
</switch>
</inSequence>
...
</resource>
</api>

Response message not being accepted by WeChat

So we got our application accepted in the wechat debug console, and are looking to respond with rich media type messages.
the request expected from the server is as follows:
<xml>
<ToUserName>UserName</ToUserName>
<FromuserName>TestUser</FromuserName>
<CreateTime>7200</CreateTime>
<MsgId>12302</MsgId>
<Content>Test Message</Content>
</xml>
To which we reply with the following:
<xml>
<ToUserName>TestUser</ToUserName>
<FromUserName>UserName</FromUserName>
<CreateTime>7200</CreateTime>
<MsgType>news</MsgType>
<ArticleCount>1</ArticleCount>
<Articles>
<item>
<Title>Test</Title>
<Description>Test</Description>
<PicUrl>http://PICURL</PicUrl>
<Url>http://ARTICLE_URL</Url>
</item>
</Articles>
</xml>
However the application doesn't seem to be getting the requests as it was setup so the questions is:
Will requests go to the URL setup?
If so is the xml provided correct for the response and also for the messages that gets posted to the url provided?
Are there specific headers presents in the request?
Yes the Requests will go to the URL that you have setup and send a straight XML post to your script.
Check your XML there seems to be quite a few differences from the actual system input and output also check the example of working input and output XML and try this. Obviously replacing the ToUserName and FromUserName:
INPUT RESPONSE
<xml>
<ToUserName><![CDATA[gh_4456]]></ToUserName>
<FromUserName><![CDATA[123abc]]></FromUserName>
<CreateTime>1397201326</CreateTime>
<MsgType><![CDATA[text]]></MsgType>
<Content><![CDATA[test]]></Content>
<MsgId>6000934001298302633</MsgId>
</xml>
OUTPUT RESPONSE
<xml>
<ToUserName><![CDATA[123abc]]></ToUserName>
<FromUserName><![CDATA[gh_4456]]></FromUserName>
<CreateTime>1397201781</CreateTime>
<MsgType><![CDATA[news]]></MsgType>
<ArticleCount>1</ArticleCount>
<Articles>
<item>
<Title><![CDATA[Your test title]]></Title>
<Description><![CDATA[test description]]></Description>
<PicUrl><![CDATA[http://test.com/img.jpg]]></PicUrl>
<Url><![CDATA[http://test.com/]]></Url>
</item>
</Articles>
</xml>
No headers you need to worry about.
FOR OFFICIAL OA: I think your problem might be that you have not enabled developer mode yet. Even though you have setup the URL and TOKEN. Please confirm developer mode is ENABLED. Go to admin.wechat.com -> login -> function -> advanced -> developer mode should be ENABLED.
FOR SANDBOX ACCOUNT: developer mode is always enabled.
Also check your CreateTime this should be a unix timestamp.
If none of that resolves it go and look at your access logs. Find the URL wechat is posting to. Once you have the URL got to http://www.hurl.it/ change the destination type to POST and paste the URL there. Add a Header called "Content-Type" with the value "text/xml" click on add body and post your input response in there. This will give you the response that WeChat sees. I tested yours and found the ToUserName was blank, also ensure you don't have unneeded spaces or newlines there.

Getting No 'Access-Control-Allow-Origin' when sending large JSON via AJAX

I'm working on a web page that calls a REST webservice via ajax to get and insert data.
The problem is that we need to send a base64 image in a JSON. You know, the base64 image is the imaged converted to that large text: base64/fjhd7879djkdadys7d9adsdkjasjdshk...
When we try with a 1 KB image, it works.
But with a bigger file(55kb), it doesn't.
So I assume it has something to do with the maxRequest, but the error says that is No 'Access-Control-Allow-Origin'. But we havent fount any way to configure it. Please help.
By default browsers block json requests from other domains other than the page unless the json request has the Access-Control-Allow-Origin header, so you'll need to add that header to your json requests on that service or use the same domain for both.
More info here: https://developer.mozilla.org/en-US/docs/HTTP/Access_control_CORS
You can try setting the maxJsonLength to it's maximum value in the web.config file.
<system.web.extensions>
<scripting>
<webServices>
<jsonSerialization maxJsonLength="2147483647"/>
</webServices>
</scripting>
</system.web.extensions>
I know this is an old post, but for anyone who still might be having this problem, I solved it by adding two settings to Web.config as described here: https://west-wind.com/webconnection/docs/_4lp0zgm9d.htm
<system.webServer>
<security>
<requestFiltering>
<requestLimits maxAllowedContentLength="2147483647"></requestLimits>
</requestFiltering>
</security>
<!--snip-->
</system.webServer>
and
<system.web>
<httpRuntime maxRequestLength="2147483647" />
<!--snip-->
</system.web>

HttpWebRequest "keep-alive" header gets dropped

I am in NTLM hell here, hope you can help indentify what I am missing.
I am ultimately trying to deliver SSRS reports to a frame in a browser, and only the images within the reports are giving me much grief. They don't appear unless the user has Firefox and enters their credentials 2 times, first for the report, then a second time for the images in the report.
I am using HttpWebRequest to obtain the SSRS reports.
I am sending the webserver (IIS 7.5) a credential cache with "NTLM" and valid credentials to try and obtain an images from SSRS after I receive the HTML stream so that I can store them locally and refer to those, which would alleviate the users from having to re-enter credentials again and again.
I see in Fiddler that Type 1, 2 and 3 challenges are properly met during the NTLM hand shaking, however, the final response is 500 internal service error. The response text also indicates rsStreamNotFound, however, I find next to no info on what that means and I think it's misleading as to what the real problem may be.
When I use Firefox, Firefox prompts me for my network credentials for the report and then again for the images, and it gets through bringing the images back. My HttpWebRequest fails with 500 Internal Server Error, and rsStreamNotFound.
The only difference I can see in the request headers between Firefox requests and my requests is that the "keep-alive" property gets dropped from my programmatic request, and the Firefox requests have it in there.
Why do my "keep-alive" get dropped?
At this point, that is the only difference between my request and the request from Firefox, so I would like to eliminate that difference before jumping to any other conclusion.
I tried variations of:
req.KeepAlive = true;
req.PreAuthenticate = true;
and this gem:
var sp = req.ServicePoint;
var prop = sp.GetType().GetProperty( "HttpBehaviour", BindingFlags.Instance | BindingFlags.NonPublic );
prop.SetValue( sp, (byte)0, null );
Here is the CredentialCache:
CredentialCache credentialCache = new CredentialCache();
credentialCache.Add( new Uri( path ), "NTLM", NetCredentials );
... and "keep-alive" is not present in the request for my HttpWebRequest, and Firefox has it - why does mine get dropped?
Update:
I tried:
using (WebClient client = new WebClient()) {
client.DownloadFile(url, filePath);
}
...and I got 401 Unauthorized, so I tried with credentials and get 500 Internal Server Error
It is not clear from your question where you are running the code. Is it running on the desktop as an executable? Or is it running inside firefox as some sort of activex control or something similar?
Anyway, I suggest using .net tracelog facility to get a log of your transaction, and look at the logfile.
<?xml version="1.0" encoding="UTF-8" ?>
<configuration>
<system.diagnostics>
<trace autoflush="true" />
<sources>
<source name="System.Net">
<listeners>
<add name="System.Net"/>
</listeners>
</source>
<source name="System.Net.Sockets">
<listeners>
<add name="System.Net"/>
</listeners>
</source>
<source name="System.Net.Cache">
<listeners>
<add name="System.Net"/>
</listeners>
</source>
</sources>
<sharedListeners>
<add
name="System.Net"
type="System.Diagnostics.TextWriterTraceListener"
initializeData="System.Net.trace.log"
/>
</sharedListeners>
<switches>
<add name="System.Net" value="Verbose" />
<add name="System.Net.Sockets" value="Verbose" />
<add name="System.Net.Cache" value="Verbose" />
</switches>
</system.diagnostics>
</configuration>
If your app name is app.exe, create a file called app.exe.config in the same directory as the exe, and put the above contents into it. Then run the app, and a logfile should be created.
This link should have more information on getting logfiles, in case you have a problem.
creating a system.net trace log
You can put the logfile on pastebin after deleting personal information like hostnames, ipaddresses etc.
Also, give us a snippet of code that reproduces the problem. Then it will be easier to help.

Resources