因此,我正在按照UPS API的“创建运输标签”流程进行工作...我处于最后阶段,在此阶段,所有内容都经过验证,UPS将实际的运输标签以GIF格式返回给我。示例文档,这是通过XML返回的内容(我已经删除了所有其他前面的XML位)。
<GraphicImage>FSDJHSDJHJ3487EHNE9U8DY9VHRFV89SDFHFSDJHFSDIDFH
SJKDFSJKDFSJIU9GFIUGJIFDUJG9UKGLDJFDKJDGKJDFKGDJLDFKSJGKDFJDKGFDG9E0ER
IJGE39IWURE9U9ER0UW9R0UR9WEGU9URE9WGUW90U90GRUG90GERUG9REUGWERGJIO
JGIODFGUIOFDUGIOFUIGRUE090U9TERUT90RUT9EU90ERUT9ERU9EUER9TUT9R0UTE90R
U9TERU90RTEU9SDKHGJHGDFU</GraphicImage>
<HTMLImage>SKJJKLHGIGKHGKJHGFJGFJHDFJGHDDJFHFDJHFJHFJKDHJK
FDHJFJDFHDFJHJDFHGJDHGDFSHJKFSDHSDFJHFJSDHJKDFHFJKSHDSKJHGFDJSJDFSKSK
JJKLHGIGKHGKJHGFJGFJHDFJGHDDJFHFDJHFJHFJKDHJKFDHJFJDFHDFJHJDFHGJDHGDF
SHJKFSDHSDFJHFJSDHJKDFHFJKSHDSKJHGFDJSJDFSKHGJKDS</HTMLImage>
..我要对那个GIF数据或那个HTMLIMage数据做什么?例如,我将GIF数据通过管道传输到gif文件中-但GIF文件无法打开-我还需要做其他事情吗?
答案 0 :(得分:1)
大多数运输API的返回标签为Base 64编码的字符串(JSON或XML)。 您需要将内容从base 64转换为bite数组,然后保存它。
进行Base64转换的方式因开发平台而异,但是有很多示例。这是我刚刚找到的。
http://processrhetoric.blogspot.com/2013/01/getting-ups-shipping-label-via-their-api.html
如果使用Google Chrome浏览器,则可以通过构建以
开头的字符串来预览图像data:image/gif;base64,
然后添加图像内容(尽管您的示例内容似乎不起作用)。
data:image/gif;base64,FSDJHSDJHJ3487EHNE9U8DY9VHRFV89SDFHFSDJHFSDIDFH
SJKDFSJKDFSJIU9GFIUGJIFDUJG9UKGLDJFDKJDGKJDFKGDJLDFKSJGKDFJDKGFDG9E0ER
IJGE39IWURE9U9ER0UW9R0UR9WEGU9URE9WGUW90U90GRUG90GERUG9REUGWERGJIO
JGIODFGUIOFDUGIOFUIGRUE090U9TERUT90RUT9EU90ERUT9ERU9EUER9TUT9R0UTE90R
U9TERU90RTEU9SDKHGJHGDFU
然后将结果放入浏览器地址栏中,图像就会出现。
在JavaScript / VBScript中,使用ADODB将您从base64创建的字节作为GIF保存到磁盘。
var stream = new ActiveXObject("ADODB.Stream");
try {
if (objFSO.FileExists(strFileName)) {
objFSO.DeleteFile(strFileName);
}
stream.Type = 2; // text
stream.Charset = "ISO-8859-1";
stream.Open();
stream.WriteText(bytes);
stream.SaveToFile( strFileName, 2);
} catch (err){
return;
} finally {
if (stream.State != 0) {
stream.Close();
}
}
答案 1 :(得分:0)
For this we need two gems:
gem "wicked_pdf"
gem 'wkhtmltopdf-binary'
ups_gif_image = base64 GIF image # This is the
base64 graphicimage in the form of GIF that is returned from UPS
shipment request API
ups_base64_gif_image ="data:image/gif;base64,"+ups_gif_image
pdf_data = WickedPdf.new.pdf_from_string("<img src='"+ups_base64_gif_image+"'/>",{:orientation => 'Landscape'})
File.open('label.pdf','wb') do |pdf|
pdf.write pdf_data
pdf.close
end