Rails - resize image before upload to s3 |
You can use the rmagick gem. In your gemfile
gem 'rmagick', '2.13.2'
then bundle install.
Rmagick gem
You will also have to install ImageMagick on your system:
ImageMagick binaries
You can then use it from within your app. See this railscast:
Image Manipulation Railscast
The relevant code:
require "rmagick"
source = Magick::Image.read("octocat.png").first
source = source.resize_to_fill(70, 70)
|
Rails 3: best way to preview image before upload |
So! :) The main idea is to use the FileReader Javascript Class, which is
really handy for what you need to do.
You just have to listen to the "change" event on your file input and then
call a method that will use the "readAsDataURL()" method of the FileReader
class. Then you just have to fill the source of a "preview img tag" with
the returned result of the method...
I've wrote you a simple jsFiddle that achieves what you want. You can see
my code below:
<!-- HTML Code -->
<div class="upload-preview">
<img />
</div>
<input class="file" name="logo" type="file">
//JS File
$(document).ready(function(){
var preview = $(".upload-preview img");
$(".file").change(function(event){
var input = $(event.currentTarget);
var file = in
|
How to resize image on upload in rails app using paperclip? |
Check out the readme on github: https://github.com/thoughtbot/paperclip
Quick Start
class User < ActiveRecord::Base
attr_accessible :avatar
has_attached_file :avatar, :styles => { :medium => "300x300>",
:thumb => "100x100>" }, :default_url =>
"/images/:style/missing.png"
end
If you upload an image, you can set different styles..in your case 300px.
|
Upload image to BigCommerce by json query |
My cURL command looks like this:
curl.exe -k -s --request POST -u "shopuser:tokenkey" -H "Content-Type:
application/json" -d '{"product_id":
512,"image_file":"http://www.exhibitionsinternational.org/img/9789490693589.jpg"}'
https://store-yjybvmp.mybigcommerce.com/api/v2/products/512/images.json
I don't know what I am doing wrong, I can upload new products but no images
|
rails paperclip image upload Encoding::UndefinedConversionError ("xFF" from ASCII-8BIT to UTF-8): |
Removed support for the encode_json hook used for encoding custom
objects into JSON. This feature has been extracted into the
activesupport-json_encoder gem.
Add activesupport-json_encoder gem to Gemfile fix this issue.
|
upload image from mobile to server and shows JSON is undefined error |
I found the issue.. POST and jsonp are not compatible...So it was using the
verb GET, but it has size limitation..that's why large image is not
uploading...
SO I achieved the cross domain call using method CORS and POST and now I am
able to uplaod the image to server...
Thanks..
|
multiple Image upload fails to upload only the first image |
"upload" here $_FILES['upload'] refers to the name of the file field in the
form.
you are only ckecking if a file from the file field named upload has been
uploaded
did you maybe name the first upload field in the form differently?
|
How to upload specific List image using click on Upload button |
Try this code:
btnUpload = (Button) convertView.findViewById(R.id.btnUpload);
btnUpload.setTextColor(Color.BLACK);
btnUpload.setTag(strPath);
btnUpload.setOnClickListener(new View.OnClickListener() {
@SuppressWarnings("deprecation")
public void onClick(View v) {
// Upload
startUpload(position);
fileName=ImageList.get(position).toString()
.substring(strPath.lastIndexOf('/')+1, strPath.length());
}
});
//Upload
public void startUpload(final int position) {
Runnable runnable = new Runnable() {
public void run() {
handler.post(new Runnable() {
public void run() {
View v = lstView.
|
Upload default image if user didn't upload any |
You should first check $_FILES['userfile']['error'] === UPLOAD_ERR_OK
if it's not UPLOAD_ERR_OK, then something went wrong.
A list of errors can be found here: file-upload.errors
Example:
$uploaddir = '../photo/';
$uploadfile = $uploaddir . basename($_FILES['userfile']['name']);
if ($_FILES['userfile']['error'] === UPLOAD_ERR_OK) {
if (move_uploaded_file($_FILES['userfile']['tmp_name'], $uploadfile)) {
/** do stuff **/
}
} else {
echo "An error occurred with your upload.<br>";
switch($_FILES['userfile']['error']) {
case UPLOAD_ERR_INI_SIZE:
echo "The uploaded file exceeds the upload_max_filesize directive in
php.ini";
break;
case UPLOAD_ERR_FORM_SIZE:
echo "The uploaded file exceeds the MAX_FILE_SIZE directive that was
specified in the HT
|
Phonegap image upload fail to upload |
the path is wrong, in that case. /products/ might be at the root when you
log in, but the web user might have a different root. It's worth checking,
at least - if you upload a PHP file containing just echo(getcwd()); they
should show you what PHP thinks the path is. - @andrewsi
|
php image upload with class.upload |
Try this:
CropFactor in the form field should be
<select name="cropfactor[]" class="select-ms">
..
</select>
and in your function:
//after $id = $_GET['id']; add following
$cropfactor = $_POST['cropfactor'];
and for each of your files go through each value of $cropfactor
foreach ($files as $file) {
// ... all other codes
if ($handle->uploaded) {
//...everything else
if($cropfactor[$counter] == 1) {
$handle->image_ratio_crop = true;
} else {
$handle->image_ratio_fill = true;
}
}
}
Hope it helps.
note: code not tested.
|
json database get image setting data for json using while loop carousel type jquery json |
Look for a jquery carousel plugin.
http://vandelaydesign.com/blog/tools/jquery-carousel-plugins/
http://www.webdesigntunes.com/freebies/30-amazing-free-jquery-slider-and-carousel-plugins-of-2013/
Edit: does this help?
$data = array();
$x = 0;
while ($test = mysql_fetch_array($query)) {
$data[$x]['content'] = "<div class='slide_inner'><a
class='photo_link' href='#'><img class='photo' src='{$test['image']}'
alt='Bike'></a><a class='caption' href='#'>Sample Carousel
Pic Goes Here And The Best Part is that...</a></div>";
$data[$x]['content_button'] = "<div class='thumb'><img
src='{$test['thumb']}' alt='bike is nice'></div><p>Agile
Carousel Place Holder</p>";
$x++;
}
echo json_encode($data);
|
Perform a google image search using image upload through Android code |
Yes, Google Image Search API is currently Deprecated. But, you could use
Bing's instead. Here is an example of retrieving images using it with Java.
It is a good start for your application.
EDIT:
If you want to search by images there is an alternative called tineye. They
have an API for that.
|
Does this PHP image upload code has any secure bugs(Image files on LNMP server had been malicious replaced)? |
Yes, there are security bugs. The upload filename is controlled by the
user:
$filename = explode(".",$_FILES['upload_file']['name']);
$ext = end($filename);
the filename doesn't necessarily have to contain a dot, $ext will be the
whole filename
everyting after the last dot will end up in $ext
In both cases $ext can be freely controlled by an attacker, and seen that
you later use it in your sql query without sanitation, you have a serious
sql injection vulnerability.
You shouldn't build sql queries by concatenating strings. You're using PDO,
so do yourself a favor and use parameterized queries, it will save you a
lot of trouble.
edit:
Another vulnerability may be that your script allows you to upload any file
type, so if you didn't disable execution of php for your upload directo
|
Hide upload button when image is present, Show when Image is gone? |
Trigger the change event on click of remove button so that the logic
re-applies.
$('.moon_remove_file_button').click(function(){
$('#test').removeClass('static_preview_image');
$('#_moon_static_bg_status').change();
});
Demo
|
Jboss image upload and http access to show image |
You can add a new context to specify a path to access an external folder.
Steps for Jboss 4 and older versions:
Open your file /YOURINSTANCE_JBOSS/deploy/jboss-web.deployer/server.xml.
Define a new Context in the tag <Host name=”localhost” ...>
Example:
<Host name=”localhost” ...>
<Context path=”/myfolder” docBase=”/home/username/my_images”
reloadable=”true”></Context>
Where /myfolder will be the path that you are going to use to access your
files, and /home/username/my_images the folder where you are going to
upload your pictures.
Restart JBoss
Now you will be able to access your files with the next path:
http://yourserver:yourport/myfolder/filename
Steps for Jboss 5:
Create a new file named context.xml into your WEB-INF folder wit
|
How do you upload image and set it as featured image on wordpress using C# metaweblog api? |
I found the answer to the problem. XML-RPC alone cannot set any uploaded
image to featured image. Head over to this issue page
http://core.trac.wordpress.org/ticket/15098. The patch allows returning the
ID information of the uploaded image when using
wp.uploadFile/metaWeblog.newMediaObject. Once the image ID(not the image
URL) is returned, you can set it to wp_post_thumbnail and it should appear
as featured image. Another workaround without going this route is by
uploading the image first and you should be able to retrieve the URL of the
image. Query ID information from wordpress database table called wp_posts
where image id is equal to the name of the image uploaded. From there, you
can then set the ID to wp_post_thumbnail. Thanks a lot.
|
I'm trying to upload image and binding Gridview to display image? |
When creating a customer handler, a interface still needs to be inherited.
Please try inheriting from the "IHttpHandler" class:
public class HTTPHandler : IHttpHandler
|
Rails 4 - Customizing (json) format of response objects in Rails |
2 ways:
first: define a view, where you build and return an hash that you'll
convert to json.
controller:
YourController < ApplicationController
respond_to :json
def index
@comments = Comment.all
end
end
view: index.json.erb
res = {
:comments => @comments.map do |x|
item_attrs = x.attributes
item_attrs["username"] = calculate_username
end
}
res.to_json.html_safe
second: use gem active_model_serializers
|
Django-Postman disable email notification per user |
That code says that django-postman reads a setting (from your settings.py
file) called POSTMAN_DISABLE_USER_EMAILING, and if no value is set, it
defaults to False.
The docs say:
POSTMAN_DISABLE_USER_EMAILING
Set it to True if you do not want basic email notification to users. This
setting does not apply to visitors (refer to
POSTMAN_DISALLOW_ANONYMOUS), nor to a notifier application (refer to
POSTMAN_NOTIFIER_APP)
Defaults to: False.
However, that turns emailing on and off across the whole system. To disable
user emailing on a per-user basis as you request, this code in
postman/utils.py points to an answer:
if notification:
# the context key 'message' is already used in
django-notification/models.py/send_now() (v0.2.0)
notification.send(users=[user], label=label
|
Rails JSON API testing POST request with PARAMS in JSON |
I found my answer on a post here(RSpec request test merges hashes in array
in POST JSON params), I think what I was doing wrong concerned the
arguments to the request.
so this worked:
it "should return an error if there is no correct email" do
params = {:subscription => {:email => "andre"}}
post "/magazine_subscriptions", params.to_json, {'ACCEPT' =>
"application/json", 'CONTENT_TYPE' => 'application/json'}
end
|
How to call RestFul WCF POST service using POSTMAN or any client tool application? |
Install a tool called Fiddler and then use the below raw request.
URL:http://localhost/Sample/Service1.svc/post/createNewSurvey
User-Agent: Fiddler
Content-Type: application/json
Host: localhost
{"id":"5","Data":"sample data to be sent to server"}
|
iOS tweet image - Can I get the image url before upload? |
1) I don't see how you plan on conjuring an image URL before you upload the
image - that is a chicken/egg situation. I would recommend taking a look at
an actual image URL after you upload it to facebook, twitter, etc and try
to figure out even one character of what it would be for the next image you
upload. Regarding twitter specifically the image URL is also going to vary
depending on what upload service is being used.
2) regarding uploading the image and getting the URL why not look into
tapping into the flickr API?
|
Rails 4: How to upload files with AJAX |
Have a look into the remotipart gem:
https://github.com/JangoSteve/remotipart -- may get you all of the way
there with very little work!
|
Render nothing after upload rails without reload |
U should make ajax file upload and then handle the success,
http://malsup.com/jquery/form/
Use this plugin to do a file upload And then handle the success.
|
Rails: Upload CSV file without header |
You could just load the CSV file into an array of arrays and remove the
first row:
data = CSV.read("path/to/file.csv")
data = data[1..-1]
However this will store the data as an array of values only.
When you use headers: true it uses a hash where the keys are the column
header names.
|
CSV file upload cancel Ruby on Rails |
I don't think you should have to rely on users closing the browser window -
maybe you could use a validator to ensure that 100% of the .CSV file is
uploaded before it saves, otherwise it redirects to the main index?
|
Rails How To Upload Code To The Production Server |
If I were you I would go for Heroku first. It's free and easy and along the
way you will learn some about hosting Rails apps.
Getting started with Heroku is a good place to go first
https://devcenter.heroku.com/articles/quickstart
|
jquery file upload rails redirect |
there's a couple of things you have to consider. First, you have to be able
to get the url to the edit action. If your js is in the page and not in an
asset file, the following change should work.
jqXHR = data.submit()
.complete(function() { window.location = "#{url here}" })
you also need to use <%= %> if you are using erb instead of #{...}.
If this is in an asset file, you don't have access to instance variables so
you have to rely on the response of the server. As an example, you can set
the response to be json.
$('#fileupload').fileupload({
dataType: 'json',
add: function(json) {
jqXHR = data.submit()
.complete(function() { window.location = json.url })
}
})
since you're using json.url above, it expects you to return the url in the
json response so in your
|
AngularJS/Rails Paperclip file upload |
I progress now, i succeed to send file data via form-data content-type, the
problem is now in the rails controller, an error is launched :
undefined method `stingify_keys`
Here is the code i use to send the data :
$http({
method: 'POST',
url: url,
headers: { 'Content-Type': false },
transformRequest: function (data) {
var formData = new FormData();
formData.append("post", angular.toJson(data.post));
formData.append("image", data.image);
return (formData);
},
data: { post: $scope.post, image: $scope.image}
}).
success(function (data, status, headers, config) {
alert("success!");
}).
error(function (data, status, headers, config) {
alert("failed!");
});
And that's the data which
|
Upload Photo from iphone app to rails server |
Convert image to Data then Encode to Base64 String the save that string in
server and then when retrieving from server, decode Base64 String to data
and use [UIImage imageWithData: data];
|
Rails - Upload and parse multiple CSV files |
Well, as far as I see. This behavior shouldn't actually be happening. I
would suggest another way of doing this code, since it's looking a bit
polluted.
def import
(1..x).each do |i| #with x being the max number of files uploaded at
the same time
RatingSet.multi_uploader(params["file_#{i}".to_sym])
end
redirect_to "/multi_uploader", :flash => { :notice =>
"Successfully Uploaded." }
end
Either way, this shouldn't solve your problem. I can't tell why this is
happening to be honest.
UPDATE:
Have you considered using: <%= f.file_field :file, :multiple => true
%> instead of mutiple file_tags?
|
ruby on rails, file upload and database |
There is a reason people use gems. They provide flexibility and simplicity
into application. Gems is blessing and not using gems when you can is a
total waste of time. As for this application, please consider Carrierwave
gem. One was specifically designed for file uploads. Here is a railscast
video on how to use it. I'm sure you'll find it pretty simple and awesome
to use.
|
Upload JSON File and Parse |
Look into a JSON parser. If you go here
(http://theburningmonk.com/benchmarks/) and scroll down to JSON
Serializers, you will see a list of popular serizalizers and their
performance.
Depending on what you need out of the JSON, you can deserialize to dyanmic,
and quite easily just access members of the object with . operators. Your
other option is to use http://json2csharp.com/ to generate a class file
that matches the layout of the JSON and will allow you to deserialize into
an exact object.
As for the uploading part, I suggest you take a look over here: File Upload
ASP.NET MVC 3.0
|
How upload multiple photos at the same time?? Ruby on Rails |
I would suggest using a gem such as Carrierwave or Paperclip. In your view,
to allow multiple file upload, you may need to implement asynchronous file
upload. A very handy way to do this that uses jQuery is a plugin called
jQuery-file-upload (which can handle multiple files).
Ryan Bates has an excellent video on Railscasts jQuery File Upload on how
to do this. There's also a gem that prepackages this jQuery plugin for you,
called jquery-fileupload-rails.
|
jQuery-File-Upload Plugin integration into Rails |
I think what instruction #4 is telling you is to simply copy the various
javascript files into your custom server environment, in this case, Ruby
on Rails.
It's best to use the assets pipeline to serve up Javascript in RoR.
1) download and extract the archive to your development environment, you
want to extract the folder JQuery-File-Upload to app/assets/javascripts
directory.
when you are done you should have:
/whatever/app/assets/javascripts/JQuery-File-Upload/stuff
So now, you have to tell rails WHEN that javascript needs to be loaded.
To keep things easy we are going to assume that that javascript is needed
on EVERY page!
If your current app is fairly 'default', the javascript manifest file:
app/assets/javscripts/application.js
controls the javascript that will be incl
|
Ruby on Rails CSV upload&import - File name too long |
It could have to do with the .read call on line 2. Somehow inputFile is
turning into the contents of the csv and not the name of the file itself.
That would lead me to believe there is a problem with you setting the
inputFile variable. My guess is that .read is not working in the way you
intended it to.
|
Rails - MassAssignmentSecurity:: Error on multiple photo upload |
Just add photos_attributes to the attr_accessible list in the Product
model. Or even better, try to migrate to strong_parameters gem, will save
you sometime when you migrate to Rails 4.
Update
In create action, you create a @photo variable from params[:photo], which
is knows to return nil, yielding the object invalid always. That said, you
don't need to create that variable as Photo objects are already made for as
you use accepts_nested_attributes_for already. I understand that you need
to know if the Photos are created successfully, but you shouldn't be
worrying about it as errors from product's new photos will propagate to the
product, stopping the saving process.
|
Rails 4, NiceEdit, Carrierwave. What should i return on upload request? |
After upload image, respond with:
render json: { upload: { links: { original: @image.image_url } } }
To understand why, download uncompressed version on NicEdit download page
and check the lines:
1419..1425 - When upload finish and receives JSON response, it get a
'upload' key and call onUploaded function.
xhr.onload = function() {
try {
var res = JSON.parse(xhr.responseText);
} catch(e) {
return this.onError();
}
this.onUploaded(res.upload);
....
1443..1445 - on onUploaded function, navigates to the key inner object key
'links', attribute 'original'
onUploaded : function(options) {
this.removePane();
var src = options.links.original;
if(!this.im) {
this.ne.selectedInstance.restoreRng();
var tmp = 'javascript:nicImTe
|
Rails 4: upload attachments to Amazon S3 before saving model |
I can think of 2 approaches:
Go ahead and save the note, but have a column on the model that tells you
whether or not it's temporary. If the user clicks save, then you change
that column from temporary to permanent. You could run a rake task in the
background to clear out temporary notes that are more than a day old, etc.,
if you wanted to do that.
Put some sort of reference in the image's file name. You can't use an id,
since that won't exist yet, but you may have other unique identifiers such
as a combination of username and post title.
If you can do the 1st option, I'd say it is much preferable. It gives you
a unique ID for the note, which has the express purpose of making it
possible to reference the note externally.
|