Nginx - Lua Unable to save image file - linux

My lua code is something like this:
local savefiletarget = "/usr/local/openresty/nginx/webfolder/img/uploadedimg.jpg".
local fileToSave = io.open(savefiletarget,"w+b")
if not fileToSave then
ngx.log(ngx.NOTICE,'failed to save file : '..savefiletarget);
ngx.say('{"filename" : "'..filenametosave..'","status" : 0 ,"message":"failed to open file"}')
return
end
Log shows the error:
failed to save file : /usr/local/openresty/nginx/webfolder/img/uploadedimg.jpg
I'm using Linux server, do I require permissions to save the image?
Or is there anything I missed?

Related

How to change the location?

I'm trying to automate image uploading to Instagram using Selenium in Python. I'm successful till opening the fileDialogue but I'm not able to change the directory to where the image is located. It returns an error that ToolbarWindow32 can't be detected by AutoIt.
My code:
ActionChains(browser).move_to_element(browser.find_element_by_xpath(
"/html/body/div[8]/div[2]/div/div/div/div[2]/div[1]/div/div/div[2]/div/button")).click().perform()
handle = f"[CLASS:#32770; TITLE:Open]"
autoit.win_wait(handle, 60)
autoit.control_set_text(handle, "ToolbarWindow32", photopath) # This line give me the Error
autoit.control_set_text(handle, "Edit1", photopath)
autoit.control_click(handle, "Button1")
Take a look how this is done in _WD_SelectFiles with: https://github.com/Danp2/au3WebDriver/blob/master/wd_helper.au3
You should be able to do the same directly with python+selenium without using AutoIt.
Also take a look on:
https://github.com/Danp2/au3WebDriver/blob/master/wd_demo.au3
There is example how directly in AutoIt it is possible to do the same with WebDriver UDF without opening any FileOpenDialog :
Func DemoUpload()
; REMARK This example uses PNG files created in DemoWindows
; navigate to "file storing" website
_WD_Navigate($sSession, "https://www.htmlquick.com/reference/tags/input-file.html")
; select single file
_WD_SelectFiles($sSession, $_WD_LOCATOR_ByXPath, "//section[#id='examples']//input[#name='uploadedfile']", #ScriptDir & "\Screen1.png")
; select two files at once
_WD_SelectFiles($sSession, $_WD_LOCATOR_ByXPath, "//p[contains(text(),'Upload files:')]//input[#name='uploadedfiles[]']", #ScriptDir & "\Screen1.png" & #LF & #ScriptDir & "\Screen2.png")
; accept/start uploading
Local $sElement = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//p[contains(text(),'Upload files:')]//input[2]")
_WD_ElementAction($sSession, $sElement, 'click')
EndFunc ;==>DemoUpload

save file from url lua ubuntu

I want download mp3 file from UTL and save it to a folder.
This is my code:
local sound = HTTPS.request('https://hozory.com/translate/?target='..matches[1]..'&text='..text)
local voice = json:decode(sound)
if voice.result.Voice_link ~= "false" then
local f = assert(io.open('test.mp3', 'w'))
f:write(voice.result.Voice_link)
f:close()
But this creates an empty mp3 file.

File Partially Download with urllib.request.urlretrieve

I have this code Which is trying to retrieve file from Git Hub Repositories.
import os
import tarfile
from six.moves import urllib
import urllib.request
DOWNLOAD_ROOT = "https://github.com/ageron/handson-ml/tree/master/"
HOUSING_PATH = os.path.join("datasets", "housing").replace("\\","/")
print(HOUSING_PATH)
HOUSING_URL = DOWNLOAD_ROOT + HOUSING_PATH
print(HOUSING_URL)
print(os.getcwd())
def fetch_housing_data(housing_url=HOUSING_URL, housing_path=HOUSING_PATH):
if not os.path.isdir(housing_path):
os.makedirs(housing_path)
tgz_path = os.path.join(housing_path, "housing.tgz").replace("\\","/")
print(tgz_path)
urllib.request.urlretrieve(housing_url, tgz_path)
housing_tgz = tarfile.open(tgz_path)
housing_tgz.extractall(path=housing_path)
housing_tgz.close()
fetch_housing_data()
After Executing the code I got this Error ReadError: file could not be opened successfully. I did checked the actual file size and the file which is download after executing this code and I came to know that file is downloaded partially.
So is their any way to download the whole file ? Thanks in Advance
Finally I got the problem. It was with the link that I was using to retrieve the file. I didn't knew that RAW link should be used along with the file name (Not using file name will give you 404 Error) in Git Hub Repositories.
So I little bit of modification is needs to be done in actual code posted in my question.
That is :
Change the link from
DOWNLOAD_ROOT = "https://github.com/ageron/handson-ml/tree/master/"
To this :
DOWNLOAD_ROOT = "https://raw.githubusercontent.com/ageron/handson-ml/master/"
And this
HOUSING_URL = DOWNLOAD_ROOT + HOUSING_PATH
to
HOUSING_URL = DOWNLOAD_ROOT + "datasets/housing/housing.tgz" \\**( Actual File name is needed)**
Thank you !

Corrupted Excel File & 7zip

I have a problem with a corrupted excel file. So far I have used 7zip to open it as an archive and extract most of the data. But some important sheets cannot be extracted.
Using the l command of 7zip I get the following output :
7z.exe l -slt "C:\Users\corrupted1.xlsm" xl/worksheets/sheet3.xml
Output:
Listing archive: C:\Users\corrupted1.xlsm
--
Path = C:\Users\corrupted1.xlsm
Type = zip
Physical Size = 11931916
----------
Path = xl\worksheets\sheet3.xml
Folder = -
Size = 57217
Packed Size = 12375
Modified = 1980-01-01 00:00:00
Created =
Accessed =
Attributes = .....
Encrypted = -
Comment =
CRC = 553C3C52
Method = Deflate
Host OS = FAT
Version = 20
However when trying to extract it (or test it for that matter) I get :
7z.exe t -slt "C:\Users\corrupted1.xlsm" xl/worksheets/sheet3.xml
Output:
Processing archive: C:\Users\corrupted1.xlsm
Testing xl\worksheets\sheet3.xml Unsupported Method
Sub items Errors: 1
The method listed above says Deflate, which is the same for all the worksheets.
Is there anything I can do? What kind of corruption is this? Is it the CRC? Can I ignore it somehow or something?
Please help!
Edit:
The following is the error when trying to extract or edit the xml file through 7zip:
Edit 2:
Tried with WinZip as well, getting :
Extracting to "C:\Users\axpavl\AppData\Local\Temp\wzf0b9\"
Use Path: yes Overlay Files: yes
Extracting xl\worksheets\sheet2.xml
Unable to find the local header for xl\worksheets\sheet2.xml.
Severe Error: Cannot find a local header.
This might help:
https://superuser.com/questions/145479/excel-edit-the-xml-inside-an-xlsx-file
and this on too: http://www.techrepublic.com/blog/tr-dojo/recover-data-from-a-damaged-office-file-with-the-help-of-7-zip/

Download xls file from application rails 4

I am using rails 4 application, where i have a xls file in my applications public folder ,and am having a link in view page after clicking that link that xls file should download to system.no need to write anything in that file its just a default template.
I use:
view:
<%= link_to "Dowload Template", admin_job_templates_path, :file_name => 'Job_Upload_Template.xlsx' %>
controller :
def index
require 'open-uri'
file_path = "#{Rails.root}/public/Job_Upload_Template.xlsx"
send_file file_path, :filename => "Job_Upload_Template.xlsx", :disposition => 'attachment'
end
also tried send_data method
def index
require 'open-uri'
url = "#{Rails.root}/public/Job_Upload_Template.xlsx"
data = open(url).read
send_data data, :filename =>'Job Template'
end
Am getting the below error.
No such file or directory # rb_sysopen -
/home/amp/workspace/LA_Tracker/public/Job_Upload_Template.xlsx
am not able to dowload the file, Plese help.
It's telling you that file doesn't exist. Do you have the capitalization correct? Double check. Also, what happens if you type:
ls /home/amp/workspace/LA_Tracker/public/Job_Upload_Template.xlsx
into the command line? Can your OS find the file?

Resources