Now in the interface to iOS, encountered some picture upload problem, now can receive the iOS came from Base64 encoded data. Do I need to decode? How does decoding need to be processed to upload images to the server and retrieve URLs from the server to be stored in the database? Seek the guidance of the Great God. I am the interface written under the YII2 framework
Reply content:
Now in the interface to iOS, encountered some picture upload problem, now can receive the iOS came from Base64 encoded data. Do I need to decode? How does decoding need to be processed to upload images to the server and retrieve URLs from the server to be stored in the database? Seek the guidance of the Great God. I am the interface written under the YII2 framework
I used base64 when I was crafting canvas images on the front.
YII2 processing
1. Read the base64 encoded data "=" $data
2. $data = Base64_decode ($data);//data is the binary data.
3. Assume that there is a upload folder under the Web directory with the file name MD5 (Microtime (TRUE)). JPG ' = $filename
4.file_put_contents (Yii:: $app->basepath. ' /web/upload/'. $filename, $data);
5.url = Yii:: $app->urlmanager->createabsoluteurl (['/']). ' upload/'. $filename
The first figure is the base64 encoded data from iOS, and the second one is the data that I base64_decode () output after decoding. These are the HTTP transmissions I simulated on postman. Why is the decoded data garbled?