I want to show media files in my iOS files. The media file can be audio, video, pdf or doc file.
In JSON file I am getting base64 encoded data. According to its media type I wants to show in view or WebView.
How to achieve this?
I tried below code,
// NSData from the Base64 encoded str NSData *nsdataFromBase64String = [[NSData alloc] initWithBase64EncodedString:base64Encoded options:0]; NSLog(@"NSdata from base64: %@", nsdataFromBase64String);
but, in the output, I am getting a null value.
How to decode that base64 encoded data and how to show that media according to its type?
This question already has an answer here:
In JSON response I am getting base64 encoded data. I know how to decode that base64 file.I saw an example on one website https://www.base64decode.net/base64-image-decoder this will gives the decoded file, file name, and type.
This is an online decoder, what I want is that I want to decode that data wants to know the file type also I want to show that file into iOS app.
The file type can be an image/gif file, pdf/doc/text file, audio/video file.
According to that file type I want to show in view.
How to achieve this feature in my iOS App?
Here is like for JSON file,https://drive.google.com/file/d/1gLLx-nWF3qZ7xJj8ntaOQplO-jalbwtS/view?usp=sharing
So I have an image cropper and its allowing the user to set the size of the image. The image returned after it is cropped is in this form:
However, when I try to decode this, i'm told that it is not in the correct format... What is going on here?
EDIT: I'm using
var base64 = require('base-64'); base64.decode(string);
EDIT: Full return value: https://pastebin.com/vsHBq3pR
I am using Gmail API to read emails from Gmail account.
In the body I am replacing some chars which are needed as I read in the forums:
String codedBody = body.Replace("-", "+"); codedBody = codedBody.Replace("_", "/");
Problem is that when I try to convert it
byte data = Convert.FromBase64String(codedBody);
there is an exception which is firing with some emails:
System.FormatException: 'The input is not a valid Base-64 string as it contains a non-base 64 character, more than two padding characters, or an illegal character among the padding characters.'
The string which is coming from the request is:
What is causing this problem?
Encoding is new to me in Python, and I am trying to understand it. Apologies if this has been asked and answered already.
I am trying to encode a Python list and decode it.When I am trying to encode a list directly, I am hitting an error like below.
>>> my_list = [1, 2, 3]>>> encoded_list = base64.b64encode(my_list)Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/base64.py", line 54, in b64encode encoded = binascii.b2a_base64(s)[:-1]TypeError: b2a_base64() argument 1 must be string or buffer, not list
To fix it, I converted the list object to a string and passed it to the encode function and I was able to successfully encode it.
>>> encoded_list = base64.b64encode(str(my_list))>>> encoded_list'WzEsIDIsIDNd'
When I try to decode it, I get a decoded string like below.
>>> decoded_list = base64.b64decode(encoded_list)>>> decoded_list'[1, 2, 3]'>>> type(decoded_list)<type 'str'>
But my original intention was to encode and decode a list and not convert the list to a string and then string to list.
Pretty sure this is not the right way to encode objects like dict or a list. If that's the case, Can someone please enlighten me on how to encode/decode non string objects in Python?
Thanks very much.