标签: binary-data

通过Javascript将二进制数据下载为文件

我正在对一个返回二进制数据的API进行ajax调用.我想知道是否可以获取二进制数据并在新窗口中为客户端显示它?这就是我现在正在做的事情.问题是,文档打开了,但它完全是空白的.

$.ajax({
    type: "POST",
    url: apiURL,
    data: xmlRequest,
    complete: function(xhr, status) {
        var bb = new window.WebKitBlobBuilder();

        // Append the binary data to the blob
        bb.append(xhr.responseText);

        var blobURL = window.webkitURL.createObjectURL(bb.getBlob('application/pdf'));
        window.open(blobURL);
    }
});
Run Code Online (Sandbox Code Playgroud)

有任何想法吗?

javascript jquery html5 binary-data

7
推荐指数
1
解决办法
2万
查看次数

使用compojure从数据库提供二进制文件

我有以下路线定义:

(require '[compojure.core :as ccore]
         '[ring.util.response :as response])

(def *main-routes*
     (ccore/defroutes avalanche-routes
       (ccore/GET "/" [] "Hello World 2")
       (ccore/GET "/images/:id" [id] (get-image-response id))))
Run Code Online (Sandbox Code Playgroud)

在此示例中,请求/像魅力一样工作并返回预期的Hello World 2.

get-images-response方法定义如下:

(defn get-image-response
  [id]
  (let [record (db/get-image id false)]
    (-> (response/response (:data record))
        (response/content-type (:content-type record))
        (response/header "Content-Length" (:size record)))))
Run Code Online (Sandbox Code Playgroud)

虽然我得到了404,但是二进制文件的服务还没有完成.有什么想法吗?

编辑:好的,问题与正在请求图像的事实有关/images/name.jpg.一旦我删除.jpg了处理程序被调用.所以问题是如何匹配除扩展名之外的任何内容?

clojure binary-data compojure

6
推荐指数
2
解决办法
2999
查看次数

如何在PostgreSQL数据库中存储视频?

我将图像文件(如jpg,png)存储在PostgreSQL数据库中.我在这里找到了有关如何做到的信息.

同样,我想将视频存储在PostgreSQL数据库中.我在网上搜索 - 有人说应该使用数据类型bytea来存储二进制数据.

你能告诉我如何使用bytea专栏来存储视频吗?

database postgresql file-io binary-data

6
推荐指数
3
解决办法
1万
查看次数

"二进制"数字与我的日常编程有何关系?

我正在努力发展对整个编程的深刻理解.我理解教科书对"二进制"的定义,但我不明白的是它究竟是如何适用于我的日常编程的?

尽管我最好地尝试研究和理解这个概念,但"二进制数"与......以及"常规"数字的概念完全失去了.

我是一个最初通过在早期的DOS Basic和C中构建愚蠢的小冒险游戏来自学编程的人,现在我用PHP,JavaScript,Rails和其他"网络"语言完成了大部分(呃,所有)我的工作.我发现这些逻辑中的大部分是用这些更高级别的语言抽象出来的,我最终觉得我缺少许多继续进步和编写更好代码所需的工具.

如果有人能指出我在一个良好,可靠的实践学习资源的方向,或在这里解释它,它将受到大力赞赏.

我并不是在寻找"定义"(我现在已经阅读了几次维基百科页面),但更多的方向是如何将这些新发现的知识完全包含在我的日子中的二进制数字中.一天编程,如果有的话.我这些天主要用PHP编写,因此对该语言的引用将非常有用.

编辑:正如所指出的那样..二进制是一个数字的表示,而不是一个完全不同的系统.所以为了修改我的问题,使用数字的二进制表示而不仅仅是...数字有什么好处(如果有的话).

php python binary binary-data

6
推荐指数
1
解决办法
1001
查看次数

如何将二进制字符串转换为java中2字节的字节数组

我有二进制字符串String A = "1000000110101110".我想将此字符串转换为长度为2的字节数组java

我已经接受了这个链接的帮助

我试图通过各种方式将其转换为字节

  1. 我先将该字符串转换为十进制,然后将代码应用于存储到字节数组中

    int aInt = Integer.parseInt(A, 2);
            byte[] xByte = new byte[2];
        xByte[0] = (byte) ((aInt >> 8) & 0XFF);
        xByte[1] = (byte) (aInt & 0XFF);
        System.arraycopy(xByte, 0, record, 0,
                xByte.length);
    
    Run Code Online (Sandbox Code Playgroud)

但是存储到字节数组中的值是负数

xByte[0] :-127
xByte[1] :-82
Run Code Online (Sandbox Code Playgroud)

哪个是错误的值.

我也试过用

byte[] xByte = ByteBuffer.allocate(2).order(ByteOrder.BIG_ENDIAN).putInt(aInt).array();
Run Code Online (Sandbox Code Playgroud)

但它会在上面的行中引发异常

  java.nio.Buffer.nextPutIndex(Buffer.java:519)     at
  java.nio.HeapByteBuffer.putInt(HeapByteBuffer.java:366)   at
  org.com.app.convert.generateTemplate(convert.java:266)
Run Code Online (Sandbox Code Playgroud)

我现在该怎么做才能将二进制字符串转换为2字节的字节数组?是否有任何内置函数java来获取字节数组

java binary byte bytearray binary-data

6
推荐指数
1
解决办法
5058
查看次数

在Parse(Android)中保存和恢复照片和视频

我正在查看Parse Android文档并看到要保存照片和视频,您必须new ParseFile使用名称和byte []数据初始化并保存它.

将图像Uri和视频Uri转换为字节数组的最简单方法是什么?

以下是我尝试的解决方案:

mPhoto = new ParseFile("img", convertImageToBytes(Uri.parse(mPhotoUri)));
mVideo = new ParseFile ("vid", convertVideoToBytes(Uri.parse(mVideoUri)));

private byte[] convertImageToBytes(Uri uri){
    byte[] data = null;
    try {
        ContentResolver cr = getBaseContext().getContentResolver();
        InputStream inputStream = cr.openInputStream(uri);
        Bitmap bitmap = BitmapFactory.decodeStream(inputStream);
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        bitmap.compress(Bitmap.CompressFormat.JPEG, 100, baos);
        data = baos.toByteArray();
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    }
    return data;
}

private byte[] convertVideoToBytes(Uri uri){
    byte[] videoBytes = null;
    try {
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        FileInputStream …
Run Code Online (Sandbox Code Playgroud)

android bytearray binary-data parse-platform

6
推荐指数
1
解决办法
3741
查看次数

为什么PHP substr()会改变ASCII回车字节?

我打算使用一个长字符串来操作大量的位标志,将结果字符串保存在Redis中.然而,偶然发现了一个php bug(?).包含00001101读取位的字节substr()返回意外值:

$bin = 0b00001101;  // 13 - ASCII Carriage return
$c = substr($bin, 0, 1);    // read this character
printf("Expectation: 00001101, reality: %08b\n", $c); // 00000001
Run Code Online (Sandbox Code Playgroud)

Ideone

substr()二元安全的假设是错误的吗?还试过mb_substr(),将编码设置为8bit完全相同的结果.

php binary-data substr

6
推荐指数
1
解决办法
557
查看次数

PHP中的正则表达式二进制模式搜索

我试图在字符串中查找并替换二进制值:

$str = '('.chr(0x00).chr(0x91).')' ;
$str = preg_replace("/\x00\x09/",'-',$str) ;
Run Code Online (Sandbox Code Playgroud)

但我得到"警告:preg_replace():正则表达式中的空字节"错误消息.

如何在Regex/PHP中处理二进制值?

php regex binary-data binary-search

6
推荐指数
1
解决办法
3570
查看次数

将字节转换为二进制字符串

我需要解码一个 base64 字符串并获取一大块二进制文件。

Postgres 中是否有 SQL 函数可以简单地将 abytea转换为二进制字符串表示?
(例如“00010001010101010”。)

postgresql binary-data bytea

6
推荐指数
2
解决办法
8351
查看次数

当我打开 Salesforce 附件时,它已下载,但 pdf 为空

我正在使用 Rest API 获取附件正文。

\n
var config = {\n                method: 'get',\n                url: '<Domanin>/services/data/v48.0/sobjects/Attachment/00PD000000HQD68MAH/Body',\n                headers: {\n                    'Authorization': `Bearer ${\n                        accessToken\n                    }`,\n                    'content-type':'application/pdf'\n                },\n            };\n\n       let rawData = await axios(config);\n       rawData = rawData.data\n\n\n
Run Code Online (Sandbox Code Playgroud)\n

我正在获取这种格式的 PDF 数据

\n
%PDF-1.5\n%\xc3\x93\xc3\xb4\xc3\x8c\xc3\xa1\n1 0 obj\n<<\n
Run Code Online (Sandbox Code Playgroud)\n

在客户端,我试图将其作为可下载文件,但我得到的是空白 pdf。实际的 pdf 包含 2 页,下载的 pdf 也包含两页,但它们是空白的。

\n

客户端代码:

\n
 var downloadLink = document.createElement('a');\n            downloadLink.target = '_blank';\n            downloadLink.download = 'test.pdf';\n\n            // convert downloaded data to a Blob\n            var blob = new Blob(([rawData]), {type: 'application/pdf'});\n\n            // create an object URL …
Run Code Online (Sandbox Code Playgroud)

javascript blob salesforce binary-data arraybuffer

6
推荐指数
1
解决办法
648
查看次数