[英]Decrypt Salesforce text blob Body via Javascript
I have some Javascript where I extract the Body of a static resource file: 我有一些Javascript,我提取静态资源文件的Body:
function test() {
var query = sforce.connection.query("Select Body from StaticResource where Name = 'StaticResourceFile'");
var records = query.getArray("records");
var body = records[0].Body;
I have access to the body now, but it appears to be encrypted. 我现在可以访问正文,但它似乎是加密的。 How do I decrypt it?
我该如何解密?
Via Apex, you can do it like this, but with Javascript not so: 通过Apex,您可以这样做,但使用Javascript不是这样:
Blob blob = [Select Body from StaticResource where Name = 'StaticResourceFile'].Body;
string body = blob.toString(); // actual file contents!
If this is the object you are interacting with it looks like the data is probably Base64 encoded. 如果这是您正在与之交互的对象,则看起来数据可能是Base64编码的。 You will need to decode it somehow.
你需要以某种方式解码它。 This question seems to cover a number of options to perform the decoding in Javascript.
这个问题似乎涵盖了在Javascript中执行解码的许多选项。
Going off of bronsoja's answer, I searched around for a Salesforce-provided Base64 method. 关于bronsoja的回答,我搜索了Salesforce提供的Base64方法。 I found one, in the AJAX toolkit file 'connection.js':
我在AJAX工具包文件'connection.js'中找到了一个:
<script type="text/javascript" src="/soap/ajax/22.0/connection.js" />
<script type="text/javascript">
function test() {
var test = sforce.connection.query("Select Body from StaticResource where Name = 'StaticResourceFile'");
var records = test.getArray("records");
var contents = sforce.Base64Binary.prototype.decode(records[0].Body);
</script>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.