I want to download photos from my website after zipping. I am using rubyZip gem but unable to zip remote files. Following is the scenario:
I am trying to zip content from server. Content is something like this
http://myApplication.s3.amazonaws.com/xxxxxxxx/image/image1.jpeg,
So in "zipfile.add( attachment.document_file_name, attachment.document.url)", i assigned following values:
document_file_name = image1.jpeg/image2.jpeg/image3.jpeg
document.url = http://myApplication.s3.amazonaws.com/xxxxxxxx/image
Now here I am getting following error:
No such file or directory - myApplication.s3.amazonaws.com/xxxxxxxx/image
This gem is working fine if I zipped files from local file system (e.g: /home/user/images) but not for remote files.
Is I am doing something wrong? Can someone help me out? Or any other gem which can do this?
Thanks,
-Tahniyat
What you can do is read it first from s3 write it directly to the archive file (put archive file to your temporary directory), serve it then delete the temp archive file. Here's a little snippet:
require 'zip/zip'
s3 = Aws::S3.new(S3_KEY, S3_SECRET)
bucket_gen = Aws::S3Generator::Bucket.create(s3, S3_BUCKET)
archive_file = "#{Rails.root}/tmp/archive.zip"
Zip::ZipOutputStream.open(archive_file) do |zos|
list_of_files_to_loop.each do |file|
filename = file.filename
url = "#{S3_PATH}/#{filename}"
signed_url = bucket_gen.get(URI.unescape(URI.parse(URI.escape(url)).path[1..-1]), 1.minute)
zos.put_next_entry(filename) # Give it next file a filename
zos.print(URI.parse(signed_url).read) # Add file to zip
end
end # Write zip file
# TODO: Serve file
# TODO: Delete archived file from tmp directory
Reference:
http://rubyzip.sourceforge.net/classes/Zip/ZipOutputStream.html
Related
I have a zip file containing the following structure (this is the root of the archive, not nested in a top-level folder, which I understand is a common cause of errors for aws-s3-lambda deployments):
- support/
- shared.js
- one.js
- two.js
and then in one.js and two.js:
var shared = require("./support/shared");
// ...
When I run this code locally, it works. I use the aws-sdk to upload the zip file to AWS-S3 and then use aws.lambda.createFunction() to create a function with that name and handler and everything. The created function DOES show up in my Lambda dashboard, but when I test it, I get "Cannot find module './support/shared'". I have also tried var shared = require("./support/shared.js"); and that gives "Cannot find module './support/shared.js'".
This is for runtime node6.10. The filename cases are correct for case-sensitive lambda.
Shouldn't this work?? What's the gotcha?
Is there a way to verify the file structure that Lambda is working in to show that the additional ./support/shared.js file actually made it to the working directory or whatever it uses?
The gotcha is that the zip file created on a windows machine has the wrong chmod permissions set in it for when AWS unpacks it. The files are there, but inaccessible but node just gives a generic warning about not found instead of that the folder access is denied.
I am doing a project using ruby on rails which requires reading a pdf from web(link provided by users) and store in amazon S3 bucket.
Rails version 3.2
Ruby version 2.1.5
My sample code
require 'open-uri'
data = open('http://www.cbu.edu.zm/downloads/pdf-sample.pdf')
path = "pdf_files/123/sample.pdf"
AwsWrapper::S3Object.store(path, data, S3_CONFIG[:bucket], :content_type => 'pdf')
Above code stores that file in S3 but while opening the file I can't see data. It showing error message like Failed to load PDF document I am new to RoR. Please help me. Thanks in advance.
I downloaded this Lua module and installed it with make. However, when I try to use it in my code, I get the following error:
VirtualBox:~/Downloads$ lua socket_test.lua
lua: socket_test.lua:1: module 'nixio.util' not found:
no field package.preload['nixio.util']
no file './nixio/util.lua'
no file '/usr/local/share/lua/5.1/nixio/util.lua'
no file '/usr/local/share/lua/5.1/nixio/util/init.lua'
no file '/usr/local/lib/lua/5.1/nixio/util.lua'
no file '/usr/local/lib/lua/5.1/nixio/util/init.lua'
no file '/usr/share/lua/5.1/nixio/util.lua'
no file '/usr/share/lua/5.1/nixio/util/init.lua'
no file './nixio/util.so'
no file '/usr/local/lib/lua/5.1/nixio/util.so'
no file '/usr/lib/i386-linux-gnu/lua/5.1/nixio/util.so'
no file '/usr/lib/lua/5.1/nixio/util.so'
no file '/usr/local/lib/lua/5.1/loadall.so'
no file './nixio.so'
no file '/usr/local/lib/lua/5.1/nixio.so'
no file '/usr/lib/i386-linux-gnu/lua/5.1/nixio.so'
no file '/usr/lib/lua/5.1/nixio.so'
no file '/usr/local/lib/lua/5.1/loadall.so'
stack traceback:
[C]: in function 'require'
socket_test.lua:1: in main chunk
[C]: ?
And the first line of my code:
local nixio = require "nixio", require "nixio.util"
Any help would be appreciated!
I see these options:
Try make install and hope that it works. Perhaps set some variable such as PREFIX nothing.
Manually move dist/usr/local/share/lua/5.1/nixio to /usr/local/share/lua/5.1/nixio and dist/usr/local/lib/lua/5.1/nixio.so to /usr/local/lib/lua/5.1/nixio.so.
Add the dist paths to the environment: LUA_CPATH='dist/usr/local/lib/lua/5.1/?.so;;' and LUA_PATH='dist/usr/local/share/lua/5.1/?.lua;;'.
Add the dist paths in Lua: package.cpath='dist/usr/local/lib/lua/5.1/?.so;'..package.cpath and package.path='dist/usr/local/share/lua/5.1/?.lua;'..package.path.
i am currently attempting to do a diff using review board but keep getting an ambiguous error message:
Error uploading diff
Your review request still exists, but the diff is not attached.
The debug messages do not give much away either, no errors whatsoever....
>>> RBTools 0.4.1
>>> Home = /home/tom
>>> HTTP GETting api/
>>> HTTP GETting http://127.0.0.1/api/info/
>>> Using the new web API
Index: /trunk/0.1/scripts/configure-apache.sh
===================================================================
--- /trunk/0.1/scripts/configure-apache.sh (revision 143)
+++ /trunk/0.1/scripts/configure-apache.sh (working copy)
## -1,5 +1,5 ##
#! /bin/bash
-
+echo hello
cd ..
#SRCHEAD="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
SRCHEAD=$SRC_HEAD
This is what my ".reviewboardrc" file contains:
REVIEWBOARD_URL = "http://127.0.0.1/"
the repository path is: "https://XXX/svn/infinity/trunk/0.1"
does anyone know where i can start in order to resolve this issue i am seeing?
thanks in advance
The problem you are facing may be that the relative path in the diff file is not correlated with the path of the repository as it is configured in Reviewboard.
Reviewboard, in order to find in the repository the files mentioned in the diff, will concatenate the URLs like this:
URL of the repo as configured in Reviewboard
+
optionally - the Base directory as it appears in the
Reviewboard Upload diff dialog - which can be absolute/complete
but also relative(!)
+
the relative path of the modified file as it appears in the diff file.
All these must be correlated.
Therefore, in your case, if your repository configured URL is:
https://XXX/svn/infinity/trunk/0.1
and your relative path in the diff file is:
/trunk/0.1/scripts/configure-apache.sh
... that will not work because the resulting absolute path of the file in the repo will be incorrect:
https://XXX/svn/infinity/trunk/0.1/trunk/0.1/scripts/configure-apache.sh
Possible solutions would be:
Your URL for SVN should be configured in Reviewboard like this:
https://XXX/svn/infinity
OR
The diff should be created at a lower level in the folders hierarchy - in this case it should be done at ../0.1/ level so that the path in the diff file results in /scripts/configure-apache.sh
HTH!
a workaround is to do a manual svn diff and save to a file and then compare the working copy with the trunk in the web ui
This is very strange behavior I have noticed while developing Plugin.
I have a file in the bundle that has to be loaded for wizard.
I tried to load the file in eclipse using following code.
Bundle bundle = Platform.getBundle(MTPAppPlugin.getDefault()
.getBundle().getSymbolicName());
URL fileURL = bundle.getEntry(relativeFilePath);
File file = new File(FileLocator.resolve(fileURL).toURI());
But this didnt worked in MyEclipse.So I used other way for my eclipse
url = new URL("platform:/plugin/"
+ MTPAppPlugin.getDefault().getBundle().getSymbolicName()
+ relativeFilePath);
InputStream inputStream = url.openConnection().getInputStream();
in = new BufferedReader(new InputStreamReader(inputStream));
Now I need to know is there any common way to load the file for eclipse & My Eclipse?
The first one will not work if you have space in your folder path like C:\program files....
The first one seems to be correct. What was the error given in MyEclipse?