Chris Guanzon Active Member Licensed User Longtime User Jul 3, 2023 #1 Hello everyone How can I convert a base64 string to an image and save it? I have a server and a web app. What I want to achieve is that from the web app, the user will send a POST request with a base64 string. The server will then convert the base64 string to an image and save it inside a folder.
Hello everyone How can I convert a base64 string to an image and save it? I have a server and a web app. What I want to achieve is that from the web app, the user will send a POST request with a base64 string. The server will then convert the base64 string to an image and save it inside a folder.
Johan Schoeman Expert Licensed User Longtime User Jul 3, 2023 #2 There is an example in the code in this posting QR Code - "Store" image/bitmap in a QR Code See attached B4A project: 1. It takes an image (png or jpg) and convert it into a byte array 2. The byte array is converted into a Base64 String 3. The String is then converted into a QR Code (bitmap) 4. Use the QR Code bitmap and decodes it into a string (Base64) 5. Convert the Base64 string... www.b4x.com Upvote 0
There is an example in the code in this posting QR Code - "Store" image/bitmap in a QR Code See attached B4A project: 1. It takes an image (png or jpg) and convert it into a byte array 2. The byte array is converted into a Base64 String 3. The String is then converted into a QR Code (bitmap) 4. Use the QR Code bitmap and decodes it into a string (Base64) 5. Convert the Base64 string... www.b4x.com
Chris Guanzon Active Member Licensed User Longtime User Jul 3, 2023 #3 Johan Schoeman said: There is an example in the code in this posting QR Code - "Store" image/bitmap in a QR Code See attached B4A project: 1. It takes an image (png or jpg) and convert it into a byte array 2. The byte array is converted into a Base64 String 3. The String is then converted into a QR Code (bitmap) 4. Use the QR Code bitmap and decodes it into a string (Base64) 5. Convert the Base64 string... www.b4x.com Click to expand... Is this applicable for b4j? The library used in the sample. Upvote 0
Johan Schoeman said: There is an example in the code in this posting QR Code - "Store" image/bitmap in a QR Code See attached B4A project: 1. It takes an image (png or jpg) and convert it into a byte array 2. The byte array is converted into a Base64 String 3. The String is then converted into a QR Code (bitmap) 4. Use the QR Code bitmap and decodes it into a string (Base64) 5. Convert the Base64 string... www.b4x.com Click to expand... Is this applicable for b4j? The library used in the sample.
Erel B4X founder Staff member Licensed User Longtime User Jul 3, 2023 #4 Code: Dim su As StringUtils Dim b() As Byte = su.DecodeBase64(...) File.WriteBytes(.., .., b) Upvote 0
Chris Guanzon Active Member Licensed User Longtime User Jul 3, 2023 #5 Erel said: Code: Dim su As StringUtils Dim b() As Byte = su.DecodeBase64(...) File.WriteBytes(.., .., b) Click to expand... Thank you Sir @Erel B4X: Dim su As StringUtils Dim b() As Byte = su.DecodeBase64(b64string) File.WriteBytes(File.Combine(File.DirApp, "www/assets/images/"), $"filename.png"$, b) Upvote 0
Erel said: Code: Dim su As StringUtils Dim b() As Byte = su.DecodeBase64(...) File.WriteBytes(.., .., b) Click to expand... Thank you Sir @Erel B4X: Dim su As StringUtils Dim b() As Byte = su.DecodeBase64(b64string) File.WriteBytes(File.Combine(File.DirApp, "www/assets/images/"), $"filename.png"$, b)
Erel B4X founder Staff member Licensed User Longtime User Jul 3, 2023 #6 This code will fail if multiple clients upload files at one. I don't know whether it is relevant to your user case or not... Upvote 0
This code will fail if multiple clients upload files at one. I don't know whether it is relevant to your user case or not...
Chris Guanzon Active Member Licensed User Longtime User Jul 3, 2023 #7 Erel said: This code will fail if multiple clients upload files at one. I don't know whether it is relevant to your user case or not... Click to expand... What changes do I need to make in my code? This code is for the server. Upvote 0
Erel said: This code will fail if multiple clients upload files at one. I don't know whether it is relevant to your user case or not... Click to expand... What changes do I need to make in my code? This code is for the server.
Erel B4X founder Staff member Licensed User Longtime User Jul 5, 2023 #8 You need to use a unique file name for each request. Otherwise the file will be overwritten Upvote 0
Chris Guanzon Active Member Licensed User Longtime User Jul 6, 2023 #9 Erel said: You need to use a unique file name for each request. Otherwise the file will be overwritten Click to expand... B4X: dim filename as string = req.getparameter("filename") Dim su As StringUtils Dim b() As Byte = su.DecodeBase64(b64string) File.WriteBytes(File.Combine(File.DirApp, "www/assets/images/"), $"${filename}.png"$, b) Upvote 0
Erel said: You need to use a unique file name for each request. Otherwise the file will be overwritten Click to expand... B4X: dim filename as string = req.getparameter("filename") Dim su As StringUtils Dim b() As Byte = su.DecodeBase64(b64string) File.WriteBytes(File.Combine(File.DirApp, "www/assets/images/"), $"${filename}.png"$, b)