I have a file stream generated by .xlsm file as savon response ruby. How do I decode or convert the stream and save it to file_name.xlsm?
#body=
"http://schemas.xmlsoap.org/soap/envelope/\">http://tempuri.org/\">212706.0_PCT.xlsmhttp://tempuri.org/\">UEsDBBQABgAIAFs+Lk1un6t7iQIAAMkWAAATAAgCW0NvbnRlbnRfVHlwZXNdLnhtbCCiBAIooAACAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA...........
Use the Nokogiri gem to extract the content from the element in #body. Then use Base64.decode64() to convert the data into binary and finally write it to a file.
Related
There is a Web Service that is running in an external system. The Web Service expects an XML file which is Base64 encoded.
In my ABAP program, I have the XML that I want to post to the Web Service in a XSTRING variable.
The issue here is that the Base64 version of a string and a file which contains the the same string is inherently different.
The most direct solution that I know is to write the string to a file and then convert the file into Base64 and post it to the Web Service. The problem here is that the XML string that I have to too sensitive to be stored in the file system even temporarily.
So my question:
Is there a way to create a file during runtime in memory, add the XML that I have into that file in memory and finally convert it to a Base64 string, all during the runtime without ever using the actual file system.
DATA: lv_xstring TYPE xstring.
xstring = '<document>some xml data</document>'.
xstring --> into a file in memory --> convert to a Base64 string
You can directly convert string or xstring to base64 in ABAP. Check SCMS_BASE64_ENCODE_STR FM for xtsring to base64 string conversition.
On the other hand, generally binary data (xstring) transport as base64 encoded string in SOAP body. So may be you don't need to convert it to base64, just convert xml to xstring then assign it to method parameter.
while executing below code through python
response= S3.select_object_content(Bucket=S3_bucket_name,Key=S3_file_Key,ExpressionType='SQL', Expression="select count(*) from s3object", InputSerialization={'CSV': {"FileHeaderInfo": header_usage},'CompressionType':compressformat}, OutputSerialization={'CSV': {}},)
I am getting error like
Traceback (most recent call last):
File OutputSerialization={'CSV': {}},)
File "/usr/local/lib/python2.7/site-packages/botocore/client.py", line 320, in _api_call
return self._make_api_call(operation_name, kwargs)
File "/usr/local/lib/python2.7/site-packages/botocore/client.py", line 623, in _make_api_call
raise error_class(parsed_response, operation_name)
**ClientError: An error occurred (InvalidTextEncoding) when calling the SelectObjectContent operation: UTF-8 encoding is required. The text encoding error was found near byte 49,152.**
I searched for Invalid text Encoding in boto3 but couldn't found.
Can you please help me to check this?
Thanks in advance
The data you wish you receive has the wrong Output serialization. The output serialization Describes the format of the data that you want Amazon S3 to return in response, and you are asking it to return a format that has the wrong encoding. I cannot test your code myself because I only have small bits of it, but you need to encode your serialized output to utf-8 format, otherwise the Amazon S3 storage service can't serialize your response. Probably you need to expand OutputSerialization={'CSV': {}} to make sure that your respone is coded in UTF-8 format.
Maybe these resources can help you:
Select object content parameter guide
select Object Content description
Sadly "UTF-8 encoding is required." means that object is not matching required format.
Reference: https://docs.aws.amazon.com/AmazonS3/latest/API/API_SelectObjectContent.html
UTF-8 - UTF-8 is the only encoding type Amazon S3 Select supports.
I use webdav protocol. gem 'net_dav' it's old but usefull
when i get file through it i receive it like this \xFF\xD8\xFF\xE0\x00\x10JFIF\x00\x01\x01\x01\x00H\x00H\x00\x00\xFF\...
How to convert to real image .jpg or .png?
you will have to decode this base64 string and then save file, something like
File.open('file_name.jpg', 'wb') do|f|
f.write(Base64.decode64(base_64_encoded_string))
end
I have a problem when I POST a JPEG file with WebClient.
I have converted my "image.jpg" to byte [], I send it to the Web Service but the image is corrupted.
There is a specific way to convert a JPEG file to byte []?
Thanks for your help.
There is no specific way. Files are just files to the system it does not care if it is a image, video or a dll.
To read a file into a byte stream you can use:
File.ReadAllBytes(fileName);
I personally would use EasyHTTP (https://github.com/hhariri/EasyHttp) to post the file stream:
HttpClient client = new HttpClient();
client.Post(URL, ByteStream, ContentType);
I am trying to use ServiceStack.Text to deserialize some XML.
Code:
var buildEvent = dto.EventXml.FromXml<TfsEventBuildComplete>();
The opening xml line is:
<?xml version="1.0" encoding="UTF-16"?>
ServiceStack fails with the following error:
The encoding in the declaration 'utf-16' does not match the encoding of the document 'utf-8'.
I can see from the source of the Xml Serializer that ServiceStack uses UTF-8.
I am wondering whether ServiceStack.Text can deserialize UTF-16 and if so how? And if not, why not?
I have managed to hack my way around the issue. I'm not proud of it but....
var buildEvent = dto.EventXml.Replace("utf-16", "utf-8").FromXml<TfsEventBuildComplete>();