How to convert pull_folder and pull_file base64 contents back to original item
jbhandari opened this issue · 5 comments
This is a
- Bug report
- Question
- Freature Request
Summary
After performing driver.pull_folder('/sdcard/path_to_folder')
or driver.pull_file('/sdcard/path_to_file)
I recieved a base64 string as expected. From that point on I am unable to convert back the base64 string into the original folder/file.
Ex:
encoded_file = driver.pull_file('/sdcard/DCIM/hello.jpg')
=> 00/fipjo4llfjl.../00/00/00
- At this point how can I write the file or folder into the desired destination inside my system?
- I am trying to write the file into another file while using
Base64.decode64(encoded_file)
Environment
- Appium version (or git revision): 1.8.1
ruby_lib
version: 9.14.1- Mobile platform/version/device under test: Android
https://www.rubydoc.info/gems/appium_lib_core/1.9.0/Appium/Core/Base/Driver#pull_folder-instance_method
The returned value is decoded data. Base64.decode64
is already applied inside the method.
Thus, you need to write the result into a file named hello.zip
.
folder = driver.pull_folder('/sdcard/path_to_folder')
=> 9D/DF...\x00\x00\x00
File.write('/Users/john-doe/Desktop/hello.zip', folder)
=> Encoding::UndefinedConversionError: "\x90" from ASCII-8BIT to UTF-8
Is there a way to fix these? I have tried converting it but it has yet to work out. I am trying to transfer binary files that reside within a folder.
https://github.com/appium/ruby_lib_core/pull/129/files#diff-e6a335d78444a24741564e0fe85172c7R404 worked in my environment.
Can you share your full 9D/DF...\x00\x00\x00
with me?
What about adding .force_encoding("utf-8")
like File.write('/Users/john-doe/Desktop/hello.zip', folder.force_encoding("utf-8"))
?
resolved?
please re-open or re-create another issue if you're still facing issues
I noticed if you should have saved Base64 decoded result by pull method like File.open('/Users/john-doe/Desktop/hello.zip', 'wb') { |f| f<< folder }
to write the result as binary.