我必须将Passbook与提供PDF417条形码的网站集成,其中数据以二进制(而不是文本)编码,例如:

有没有什么方法可以在pass.json中编码这个二进制块,以便Passbook在iPhone上显示它与原始图片相同?
同样,我无法切换到基于文本的条形码,因为我不拥有数据.仅为了澄清,附图包含PDF417条形码,当解码时,包含不可打印的字符,例如NULL字符,这就是我将其称为二进制的原因.
UPDATE
这是图像解码为字节数组的方式:
01 00 01 00 02 00 E7 C4 B5 96 B8 42 94 B3 B4 75
1A D1 F2 38 92 EA B5 0E 17 5D 0B 2A AA 64 18 CC
28 62 86 E5 74 5D A3 89 09 12 6E D5 7A 1A C9 EE
BF 23 9C E1 60 AD 9E DE 92 6D E5 79 99 C7 91 …Run Code Online (Sandbox Code Playgroud) 我需要在C++中对std :: string进行简单的压缩和解压缩.我查看了这个站点,代码是用于Character数组.我想要实现的是两个功能:
std::string original = "This is to be compressed!!!!";
std::string compressed = string_compress(original);
std::cout << compressed << std::endl;
std::string decompressed = string_decompress(compressed);
std::cout << decompressed << std::endl;
Run Code Online (Sandbox Code Playgroud)
我曾尝试将boost压缩为:
std::string CompressData(const std::string &data)
{
std::stringstream compressed;
std::stringstream decompressed;
decompressed << data;
boost::iostreams::filtering_streambuf<boost::iostreams::input> out;
out.push(boost::iostreams::zlib_compressor());
out.push(decompressed);
boost::iostreams::copy(out, compressed);
return compressed.str();
}
std::string DecompressData(const std::string &data)
{
std::stringstream compressed;
std::stringstream decompressed;
compressed << data;
boost::iostreams::filtering_streambuf<boost::iostreams::input> in;
in.push(boost::iostreams::zlib_decompressor());
in.push(compressed);
boost::iostreams::copy(in, decompressed);
return decompressed.str();
}
Run Code Online (Sandbox Code Playgroud)
但是代码有时会在字符串中给出Null字符,即\ u0000.如果压缩数据包含这些空字符,我该如何处理.返回类型字符串是否正确?我怎样才能实现功能 …
我有一个包含字符串作为[]字节字段的结构,我想将其编码为JSON.但是,生成的JSON包含切片内容的非预期字符串表示形式.这是我所说的一个例子:
package main
import (
"fmt"
"encoding/json"
)
type Msg struct {
Content []byte
}
func main() {
helloStr := "Hello"
helloSlc := []byte(helloStr)
fmt.Println(helloStr, helloSlc)
obj := Msg{helloSlc}
json, _ := json.Marshal(obj)
fmt.Println(string(json))
}
Run Code Online (Sandbox Code Playgroud)
这会产生以下输出:
Hello [72 101 108 108 111]
{"Content":"SGVsbG8="}
Run Code Online (Sandbox Code Playgroud)
执行[]字节编码字符串的json.Marshal()方法是什么类型的转换.如何使用我的字符串{"Content":"Hello"}的原始内容生成JSON?
在我的apache 2.2服务器上正确激活mod_deflate,我试图通过curl命令行发送一个gzipped主体.
我见过的所有教程都说要添加-H'Content-Encoding:gzip'和gzip我的正文文件,但是这会失败:
echo '{ "mydummy" : "json" }' > body
gzip body
curl -v -i http://localhost/mymodule -H'Content-Encoding: gzip' --data-binary @body.gz
Run Code Online (Sandbox Code Playgroud)
我的apache模块接收0个字节
在我的apache error.log中如果LogLevel设置为debug我得到:
[Thu Jun 01 14:29:03 2017] [debug] mod_deflate.c(900): [client 127.0.0.1] Failed to inflate input: cannot handle deflate flags
我正在寻找一种方法来传输任何文件类型的原始文件数据与任何可能的内容(我的意思是文件和文件内容都是用户生成的)两种方式在Backbone前端使用xhr/ajax调用对抗Django后端.
编辑:也许这个问题还不清楚......
如果在IDE(例如Sublime)中打开文件,则可以查看和编辑包含该文件的实际代码.我试图把THAT原始内容为JSON这样我就可以发送到浏览器,它可以被修改,然后发回.
我发布了这个问题,因为我的印象是因为这些文件的内容可以有效地使用任何编码语言,只是对内容进行字符串化并发送它似乎是一个易于破解或利用的脆弱解决方案.内容可以包含任意数量的',",{和}这似乎打破JSON格式字符,并逃避这些字符将离开代码中的文物,将有效地打破他们(不是吗?).
如果这个假设是错误的,那也是一个可以接受的答案(只要你能指出我忽略的是什么).
我正在开发的项目是一个基于浏览器的IDE,它将从服务器接收完整的文件结构.用户可以添加/删除文件,编辑这些文件的内容,然后将其更改保存回服务器.发送/接收都必须通过ajax/xhr调用来处理.
需要Underscore/jQuery的解决方案很好,如果有专门用于管理原始文件数据的东西,我可以引入额外的库.
所以我有带有angular2的asp.net核心应用程序。现在,我想上传图像,如果我以byte []的形式上传,我设法做到了。但是后来我无法检查文件是否是后端的真实图像,因此我尝试寻找其他解决方案。.我找到了有关文件上传的博客:https : //devblog.dymel.pl/2016/09/02/upload- file-image-angular2-aspnetcore /,但对我不起作用...
对于文件上传,我使用angular2库angular2-image-upload,所以图像上传的html部分如下所示:
<image-upload [max]="1" [buttonCaption]="'Browse'" [preview]="false" (change)="onFileChange($event)"></image-upload>
<button (click)="onSaveChanges()" class="btn btn-primary float-left" type="submit">Save</button>
Run Code Online (Sandbox Code Playgroud)
然后我的angular2部分看起来像这样:
onFileChange(event: any) {
this.file = event.target.files[0];
if (event.target.files && this.file) {
var reader = new FileReader();
reader.onload = (event: any) => {
this.profilePicture = event.target.result;
}
reader.readAsDataURL(this.file);
}
}
onSaveChanges() {
this.isSaving = true;
this.country = this.state.user.country;
this.userService.userChange(this.firstName, this.lastName, this.country, this.file, this.currentPassword, this.newPassword).subscribe(success => {
this.state.user.profilePicture = this.profilePicture;
this.state.user.firstName = this.firstName;
this.state.user.lastName = this.lastName;
this.isSaving = false; …Run Code Online (Sandbox Code Playgroud) 我想使用JSON发送大字节数组(这个问题启发了我),为了减少开销,我想使用base128编码(实际上可以产生有效的json字符串)。但不幸的是,我无法找到一些在JS中进行转换的过程。我将发布过程作为对此问题的答案,但是可能是某个过程较短的人,或者是在JSON中有效发送二进制数据的更好的主意。
我有一个现有的 API 端点,可以从客户端接收数据。我想添加在该端点上接收文件和数据的功能。这是我的模型:
public class TestModel
{
public IList<IFormFile> File { get; set; }
public string Name { get; set; }
public int Age { get; set; }
public string Hobbies { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
这是我的终点:
[HttpPost]
[Route("upload")]
public async Task<ActionResult> UploadTest([FromBody] TestModel test)
{
return Ok();
}
Run Code Online (Sandbox Code Playgroud)
我目前正在使用 Postman 测试我的 API。我知道在 Postman 中,有一个选项可以发送文件作为form-data正文,但在这种情况下,我的客户需要使用form-datajson 作为数据(使用FromBody)。
我找不到办法做到这一点 - 有可能吗?如果是这样,我如何使用 Postman 发送文件视图rawjson?
海家伙,
我有从sql server数据库中检索到的图像列表(不是图像路径)...我正在将该数据表转换为json ...我的问题
如果是这样怎么做......任何建议..
我在这里使用 boost gzip 示例代码。我正在尝试压缩一个简单的字符串测试,并期望压缩字符串H4sIAAAAAAAACitJLS4BAAx+f9gEAAAA如该在线压缩器所示
static std::string compress(const std::string& data)
{
namespace bio = boost::iostreams;
std::stringstream compressed;
std::stringstream origin(data);
bio::filtering_streambuf<bio::input> out;
out.push(bio::gzip_compressor(bio::gzip_params(bio::gzip::best_compression)));
out.push(origin);
bio::copy(out, compressed);
return compressed.str();
}
int main(int argc, char* argv[]){
std::cout << compress("text") << std::endl;
// prints out garabage
return 0;
}
Run Code Online (Sandbox Code Playgroud)
然而,当我打印出转换结果时,我得到了像+I-这样的垃圾值。〜
我知道这是一个有效的转换,因为解压值返回正确的字符串。但是我需要字符串的格式是人类可读的,即H4sIAAAAAAAACitJLS4BAAx+f9gEAAAA。
如何修改代码以输出人类可读的文本?
谢谢
动机
垃圾格式与我将通过其发送压缩文本的 JSON 库不兼容。
json ×4
asp.net ×2
boost ×2
c# ×2
c++ ×2
compression ×2
gzip ×2
image ×2
javascript ×2
ajax ×1
angular ×1
apache ×1
asp.net-core ×1
backbone.js ×1
curl ×1
file-upload ×1
go ×1
ios ×1
iphone ×1
passbook ×1
post ×1
zlib ×1