Downloaded image file is corrupt - lua

I'm making a simple Lua script to download images. I get the URL of the image, and then this is my code to download it:
content = http.request(imageurl)
file = io.open("E:\\Users\\Me\\Documents\\Lua\\IMGDownload\\output.jpg", "w")
file:write(content)
print("Wrote content")
I get a 4KB file, however it isn't what I want it to be.
For reference, here is the image that I want to download:
RealImage http://cdn.akamai.steamstatic.com/steamcommunity/public/images/avatars/bd/bd05e23129b5d03ecb3f933589ff1477fbff4e92_full.jpg
This is what I actually get:
Can anyone pinpoint me as to the cause?

You probably just need to open the file with "wb" mode to get Windows to open the file in binary mode and not do line-ending conversion on you.
Try io.open("E:\\Users\\Me\\Documents\\Lua\\IMGDownload\\output.jpg", "wb").

Related

FilePond: all JPEG files are uploaded as ".jpg" - why?

I've written a small FilePond example (excellent piece of work BTW) but there is one thing that I can't understand:
When I upload, e.g., "foo.JPG" or "foo.jpeg" it is saved as "foo.jpg" on the server.
I would like to keep the file extension, but don't know how to do it.
I've tried the FileRename-plugin but the files are still saved as .jpg.
I worked out a solution. If anyone is interested I can post complete code, but basically I stored the real filename (e.g., "foo.jpeg") in metadata and extracted it on the PHP server side, and then renamed the temporary file using that name instead.
In FilePond.create:
beforeAddFile: (fileItem) => new Promise(resolve => {
fileItem.setMetadata('true_filename', fileItem.filename);
resolve(true);
}),

Upload audio file to Jodit

I'm trying to configure my Jodit editor (v.3.0) in order to be able to upload also audio files.
I've put
$config['extensions'} = ['jpg', 'png', 'gif', 'jpeg', 'wav', 'mp3'];
in my config file and it stopped giving me the error "File type is not in white list", but it doesn't appear to execute any action.
What can I try?
Thanks
First you've closed the extensions array key with a } but I think is just a mistype
For the issue: I've figure out that the mp3 I'm trying to load is actually an mpeg file, even if the extension is .mp3
How to test: got to your connector, open the file connector>vendor>jodit>application>src>components>BaseApplication.php and comment out all the "if" statement with 'File type is not in white list' (for me is near line 365).
Now try to upload the file and you'll see the real extension. Mine was mpeg and after removing the comments to the BaseApplication.php file and adding the mpeg extention to the config.php the file was uploaded as expected.
Hope this can help you and a others (even my future me searching this issue again hehehe)

Reading Image file in Opencv without ext

I am trying to download an image from URL, but it's difficult to get the complete file name and extension.
Currently, I save the downloaded image with any name and without an extension.
with open(path, "wb") as f:
f.write(request.content)
I then use opencv to read this image which has no extension and it works. How is this possible?
opencv tries magic numbers / signatures for known image formats:
https://en.wikipedia.org/wiki/Magic_number_(programming)
Implementation details:
https://github.com/opencv/opencv/blob/666be238d84c339993bf18c0798d27afd420d6be/modules/imgcodecs/src/loadsave.cpp#L209

VB6 - How to get Filename in AsyncRead Downloading Method?

I'm trying to download files which have no Normal [FILENAME].[EXTENSION] in URL, Using AsyncRead Downloading Method. There is no problem in Downloading process (It is Downloading file completely and save the file into Temp files). So i want to get Real Filename with Extension to save it to another place same as original file which is for downloading.
I can get file name while the URL is something like this:
Http://Host.com/Path/MyDoc.txt ( So i can get File name "MyDoc" and extension ".txt" easily because it specified at the URL )
But when downloading URL is something like this:
Http://Host.com/Path/download.php?File=9
I can not get the Real File name and Extension. Is there any way to get them on URLs like this?
Note: There is no problem in Downloading Process and I can download both of above files Completely. I Just want to get Filename and Extension.

unzOpen returns null while unzipping tz file in iphone

I am using ZipArchive to unzip tz files in my iphone App. It works fine when I have a sample tz file which contains text files inside it. However, my main usage is to try to unzip a tz file containing Json files. When I try to do that nothing happens as I am not able to access my file and I am not coming to a conclusion regarding to what am I doing wrong here?
Only thing I have come to know is this
_unzFile = unzOpen( (const char*)[zipFile UTF8String] );
This line of code returns me a proper _unzFile and works fine with the sample .tz file which contains .txt files. However, when I try it with my .tz file which contains a json file in it, _unzFile contains nothing (i.e 0x0). Is there any problem with UTF8String function? Or else what am I doing wrong?
Please help! Thanks.
Generally it is the problem of the zip file to be uncompressed. In my condition, I used some other files, compress them manually and decompress them with the code, the unzOpen works properly. I used ASIHTTPRequest, downloaded and renamed the zip file, I suppose it could be made wrong here. Therefore, check the zip file itself please.

Resources