相关疑难解决方法(0)

如何从base64数据字符串保存PNG映像服务器端

我正在使用Nihilogic的"Canvas2Image"JavaScript工具将画布图转换为PNG图像.我现在需要的是使用PHP将这个工具生成的base64字符串转换为服务器上的实际PNG文件.

简而言之,我目前正在做的是使用Canvas2Image在客户端生成文件,然后检索base64编码的数据并使用AJAX将其发送到服务器:

// Generate the image file
var image = Canvas2Image.saveAsPNG(canvas, true);   

image.id = "canvasimage";
canvas.parentNode.replaceChild(image, canvas);

var url = 'hidden.php',
data = $('#canvasimage').attr('src');

$.ajax({ 
    type: "POST", 
    url: url,
    dataType: 'text',
    data: {
        base64data : data
    }
});
Run Code Online (Sandbox Code Playgroud)

此时,"hidden.php"收到一个看起来像数据的数据块:image/png; base64,iVBORw0KGgoAAAANSUhEUgAABE ...

从现在开始,我非常难过.从我读过的内容来看,我认为我应该使用PHP的imagecreatefromstring函数,但我不确定如何从base64编码的字符串中实际创建一个实际的PNG图像并将其存储在我的服务器上.请帮助!

javascript php base64 html5-canvas

198
推荐指数
11
解决办法
32万
查看次数

Flutter:http post上传图片

我使用Web服务进行图像处理,它在Postman中运行良好:

邮差截图

现在我想用Dart扑灭http请求:

import 'package:http/http.dart' as http;

static ocr(File image) async {
    var url = '${API_URL}ocr';
    var bytes = image.readAsBytesSync();

    var response = await http.post(
        url,
        headers:{ "Content-Type":"multipart/form-data" } ,
        body: { "lang":"fas" , "image":bytes},
        encoding: Encoding.getByName("utf-8")
    );

    return response.body;

  }
Run Code Online (Sandbox Code Playgroud)

但我不知道如何上传图像文件,在上面的代码中我得到异常:Bad state: Cannot set the body fields of a Request with content-type "multipart/form-data".
我应该如何编写请求体?

image-uploading httprequest dart flutter

20
推荐指数
9
解决办法
2万
查看次数

如何使用Dart的HttpClient上传PDF?

我需要将一个PDF文件发布到一个远程REST API,我不能为我的生活找到它.无论我做什么,服务器都会响应我尚未将对象与file参数相关联.假设我有一个叫做PDF的文件test.pdf.这是我到目前为止所做的事情:

// Using an HttpClientRequest named req

req.headers.contentType = new ContentType('application', 'x-www-form-urlencoded');
StringBuffer sb = new StringBuffer();
String fileData = new File('Test.pdf').readAsStringSync();
sb.write('file=$fileData');
req.write(sb.toString());
return req.close();
Run Code Online (Sandbox Code Playgroud)

到目前为止,我已经尝试了几乎我write()对请求的数据的每个组合和编码,但无济于事.我尝试发送它codeUnits,我已经尝试使用a编码UTF8.encode,我尝试使用a编码它Latin1Codec,一切.我很难过.

任何帮助将不胜感激.

dart dart-io

5
推荐指数
1
解决办法
3580
查看次数

如何在dart/flutter中将图像发送到api?

我看到了其他问题,但那不是我想要的,我不想将图像上传到服务器,我不想转换为base64 ...

我只想在表单数据或其他内容中发布文件并获取返回的信息.

我有这个,但没有工作:

  void onTakePictureButtonPressed() {
    takePicture().then((String filePath) {
      if (mounted) {
        setState(() {
          imagePath = filePath;
          videoController?.dispose();
          videoController = null;
        });

        http.post('http://ip:8082/composer/predict', headers: {
          "Content-type": "multipart/form-data",
        }, body: {
          "image": filePath,
        }).then((response) {
          print("Response status: ${response.statusCode}");
          print("Response body: ${response.body}");
        });


        if (filePath != null) showInSnackBar('Picture saved to $filePath');
      }
    });
  }
Run Code Online (Sandbox Code Playgroud)

post form-data dart flutter

3
推荐指数
2
解决办法
8132
查看次数

Flutter image_picker 上传图片

我正在使用 Flutter 插件 Image_picker 选择图像,以便在选择图像后上传图像

Future<File> _imageFile;

  void _onImageButtonPressed(ImageSource source) async {
    setState(() {
      _imageFile = ImagePicker.pickImage(source: source);
    });
  }
Run Code Online (Sandbox Code Playgroud)

我在颤振文档中找到了这段代码,但它不起作用

var uri = Uri.parse("http://pub.dartlang.org/packages/create");
var request = new http.MultipartRequest("POST", url);
request.fields['user'] = 'nweiz@google.com';
request.files.add(new http.MultipartFile.fromFile(
    'package',
    new File('build/package.tar.gz'),
    contentType: new MediaType('application', 'x-tar'));
request.send().then((response) {
  if (response.statusCode == 200) print("Uploaded!");
});
Run Code Online (Sandbox Code Playgroud)

dart flutter

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