I need help for reaching my object's task target. I have got a BufferInputStream in a http component response and i need to convert these object in a pdf file. Can someone help me using component "File"? Thank you.
The HTTP Listener and Requester both will return an InputStrem...That InputStream will need to be read and converted into whatever is required downstream.
What is being received in that InputStream?
BTW - If the InputStream does not contain the PDF binary then you will need to use a third-party lib to assemble your data into a PDF format.
Related
I have the following part of code:
let client = new WebClient()
let url = "https://..."
client.DownloadFile(Url, filename)
client.Dispose()
In which code i am performing a HttpGet method in which method i get a file excel with some data.
The method is executed correctly because i get my excel file.
The problem is that the content of my file excel is like this:
I think its because i don't pass ContentType:"application/vnd.ms-excel"
So anyone can help how can I pass that ContentType in my Client in F# ?
If you want to add HTTP headers to a request made using WebClient, use the Headers property:
let client = new WebClient()
let url = "https://..."
client.Headers.Add(HttpRequestHeader.Accept, "application/vnd.ms-excel")
client.DownloadFile(Url, filename)
In your case, I think you need the Accept header (Content-Type is what the response should contain to tell you what you got).
That said, I'm not sure if this is the problem you are actually having - as noted in the comments, your screenshot shows a different file, so it is hard to tell what's wrong with the file you get from the download (maybe it's just somewhere else? or maybe the encoding is wrong?)
I want to upload an image from IOS device to Google datastore.
This is how I did it:
On client side, I use cocos2d to get image raw data. image->getData(), which returns an (unsigned char*) type. I guess it's in base64.
I set, std::string postdata = "image=" + (char *)(image->getData());.
I use cocos2d HttpClient to send the postdata to a servlet.
On the servlet, I use request.getParameter("image"); to get the image data. But I got an java.lang.IllegalArgumentException: !utf8 ERROR!
However, if I just set postdata = "image=XXXX", the servlet is able to return me "XXXX", which is what I want. So I guess the problem is:
"image=" is in UTF8, but image data is in base64.
Then servlet does not know how to decode the string and returns me !UTF8 error.
I don't know if my understanding is correct?
All I want is to let servlet receive image data and send it back to client.
Is any one know how to do it?
Thanks in advance.
Regards
I solved the problem. It's just I need to encode the image data to base64, then post it to the servlet. Thanks any way.
I have a function that retrieves PDF bytes from another Webservice. What I wanted to do is make the PDF bytes also available to others by creating an API call that returns HttpResponseMessage.
Now, my problem is I don't think that passing it through json is possible, because it converts the PDF bytes into a string?
Is there any other practical way of passing the PDF, or making the PDF visible to the requestors?
(Note: saving the PDF file in a specific folder and then returning the URL is prohibited in this specific situation)
I just solved it. There is a new paramater responseType: 'arrayBuffer' which addresses this problem. Sample: $http.post('/api/konto/setReport/pdf', $scope.konta, { responseType: 'arraybuffer' }) View my question and answer on SO: How to display a server side generated PDF stream in javascript sent via HttpMessageResponse Content
How can I Parameterize an http call parameter in soapui to read parameters from a txt file for each iteration.
If needed can the parameters be encoded(url or gzip) before the call was sent?
Any help (pointers/links/code) is greatly appreciated? Thank You
Use groovy script test step to read data from txt file and store the data in TestCase property .
Something like this would work:
String fileContents = new File('/path/to/file').text;
testRunner.testCase.setPropertyValue(property_name, fileContents);
More information about groovy script steps here.
You can access this property as ${#TestCase#property_name} in your requests. Then you can use template parameters for your request url - I've already answered about it here.
If i'm not wrong you are asking about parametrization of URL which you send as HTTP Request for your Rest call. Let me explain you with an example :
Suppose you are looking for a resource and invoking the WebService using the GET method by making use of the ResourceID already present in the DB...Parametrize it as below :
http://${#Project#HOST}:${#Project#PORT}/rest/${#Project#WebApplicationName}/Resource/${#TestCase#ResourceID}
where HOST, PORT, WebApplicationName are the Project Level properties and ResourceID is a Test Case Level property(as it may change with the test cases i.e., dynamic in nature).
This is my approach of parametrization instead of taking it from a local file. Hope this helps!
I need a snippet to check file for validity (I'm allowing users to upload xml files). So I need to check whether uploaded file is XML.
The best I can think of is just check if extension is ".xml". What if its replaced?
You can try loading it like this and catch the exception:
XDocument xdoc = XDocument.Load("data.xml"));
Presumably, if they're uploading XML, then you're going to use it for something afterwards. In this case you should validate the XML against a Schema (XSD etc) so that you know you aren't going to hit unexpected values/layouts etc.
In Urlmon.dll, there's a function called FindMimeFromData.
From the documentation
MIME type detection, or "data
sniffing," refers to the process of
determining an appropriate MIME type
from binary data. The final result
depends on a combination of
server-supplied MIME type headers,
file extension, and/or the data
itself. Usually, only the first 256
bytes of data are significant.
So, read the first (up to) 256 bytes from the file and pass it to FindMimeFromData.
If you must validate the xml (assuming you want to validate the entire thing) you can use the XmlDocument class and catch an exception if it's not XML.