search

Home  >  Q&A  >  body text

Java后台接口怎么接收Android端base64的值并转换为文件后存放在指定目录下

手机端现在需要上传附件图片,图片经过base64转码并传到接口,那接口该怎么处理?需不需要上传文件类型?怎么通过base64转换成文件呢?
这个接口已经写好了,现在需要加上上传图片功能,用base64传。
1.我这个接口需要再加上一个什么参数?
2.怎么接受base64传过来的值啊?
3.如何把值转换成图片
4.转换成图片之后如何存放到制定目录呀?

PHPzPHPz2888 days ago479

reply all(2)I'll reply

  • 阿神

    阿神2017-04-17 17:34:23

    Add 2 string parameters, one is the file name and the other is the file base64 character
    Visually, your item parameters need to be passed through the form, so the two newly added parameters are also passed through the form. You only need to add the parameters, and then let Android use the form. Just pass the parameters, springmvc will automatically inject the three parameters of the form into your method parameters, then decode the string into a byte array through the base64 decoding class, convert the byte array into a stream, and save the stream to your custom directory Next, use UUID naming to prevent conflicts, and then write the file name and saved path to the database

    reply
    0
  • 迷茫

    迷茫2017-04-17 17:34:23

    The contents of all files, regardless of type, are binary data represented by bytes.
    Base64 encoding is to encode binary data into 64 visible characters, so if you need to restore it, you only need to perform Base64 decoding.
    If you need any other parameters, just add the original file name (including extension).
    Directly decode the base64 encoding and save it with the original extension (the file name doesn’t matter), and then you can use it as the original file type.

    reply
    0
  • Cancelreply