How to read file .jpg or .pdf in binary mode to be ready for upload with API?
thanks,
blue
read file in binary mode
Re: read file in binary mode
Code: Select all
Filename := "path\to\the\file"
File := FileOpen(Filename, "r")
File.RawRead(BinData, FileLen := File.Length())
Msgbox % Filename " size: " FileLen " bytes`nFirst 2 bytes: " NumGet(BinData, 0, "UChar") " " NumGet(BinData, 1, "UChar")
Re: read file in binary mode
Hi,
Thank you for answers, but still I am missing something.
In Python code is:
That works, but I am trying to translate that code into ahk.
Caputre.jpg has 49KB, but after uploading with API has 50 KB, and can not be open.
Thanks,
blue
Thank you for answers, but still I am missing something.
In Python code is:
Code: Select all
file = open("Capture.jpg", 'rb')
print(file)
Output is: <_io.BufferedReader name='Capture.jpg'>
Caputre.jpg has 49KB, but after uploading with API has 50 KB, and can not be open.
Thanks,
blue
Re: read file in binary mode
I don't know Python, but I assume we don't need the output of print(file). What a you trying to do with the read sata?
Re: read file in binary mode
I am trying upload file using API.
For now my biggest problem is when I read that file like you and @Smile_ said I get some strange Chinese sings?!?
Blue
For now my biggest problem is when I read that file like you and @Smile_ said I get some strange Chinese sings?!?
Blue
Re: read file in binary mode
When do you get 'strange signs'?
Re: read file in binary mode
When I put variable in msgbox.
Re: read file in binary mode
You cannot display binary data with a MsgBox or other AHK commands/functions expecting a string.
Re: read file in binary mode
Aha ok
Re: read file in binary mode
Take a look
Python:
Auto-Hotkey:
The python output and the text file content 'Out.txt' (Auto-Hotkey output) are the same, so I think the problem some where else in your code.
Python:
Code: Select all
import binascii
import os
cwd = os.path.dirname(os.path.realpath(__file__))
File = open(cwd + "\\Capture.jpg", 'rb')
print(binascii.hexlify(File.read()))
Code: Select all
Filename := "Capture.jpg"
File := FileOpen(Filename, "r")
File.RawRead(BinData, FileLen := File.Length())
Loop, % FileLen
Out .= Format("{:X}", NumGet(BinData, A_Index - 1, "UChar"))
FileAppend, b'%Out%', Out.txt
Re: read file in binary mode
Thank you @Smile_ for clarification.
I was 99% sure that this is the reason, but I will try to find another way.
At the end this is good post for someone else with same problem.
Blue
I was 99% sure that this is the reason, but I will try to find another way.
At the end this is good post for someone else with same problem.
Blue