Now I am sending an interface to ios and have encountered some image upload problems. now I can receive base64 encoded data from ios. Do I need to decode it? What should I do for decoding to upload images to the server and obtain URLs from the server to store them in the database? Please kindly advise. I am now giving an interface to ios and have encountered some image upload problems. now I can receive base64 encoded data from ios. Do I need to decode it? What should I do for decoding to upload images to the server and obtain URLs from the server to store them in the database? Please kindly advise. I am writing an interface in the yii2 framework.
Reply content:
Now I am sending an interface to ios and have encountered some image upload problems. now I can receive base64 encoded data from ios. Do I need to decode it? What should I do for decoding to upload images to the server and obtain URLs from the server to store them in the database? Please kindly advise. I am writing an interface in the yii2 framework.
I used base64 for canvas image synthesis at the front end.
Yii2 processing
1. read base64 encoded data => $ data
2. $ data = base64_decode ($ data); // data is binary data
3.assume that the Web Directory contains an uploadfolder with the file name md5(microtime(true00000000.'.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 sent from ios, and the second figure is the data output after base64_decode () decoding. These are the http transmission I simulate on postman. Why is the decoded data garbled?