I have been trying to implement uploadify in my rails 3.1 app. And I followed the step mentioned here. And here is my code:
{my form code here}
- arr = []
- request.env['HTTP_COOKIE'].each_char{|c| arr.push(c[0].to_s)}
- #session = arr.join("x")
= #sermon_path = sermons_path
:javascript
$('#sermon_sermon').uploadify({
uploader: '/uploadify.swf',
script: '#{#sermon_path}',
cancelImg: 'cancel.png',
buttonText: 'Browse',
auto: true,
scriptData: { 'session_encoded': '#{#session}'}
})
This did showed uploadify button to select file to upload, but when the file is selected nothing happens. It doesn't even shows the uploaded file and no response is sent back to server.
Any help would be highly appreciated.
I newer use uploadify except in a php project but may be this other tutorial can help you. On github there is a working example and an other but with rails 2.3.4 or you can simply try this gem.
Related
I know the question has already been asked, but I’m having trouble uploading a file with karate.
I have a file called "example.pdf" in my project. I put this document in a "assets" folder
I tried to build on the example of the documentation here.
https://github.com/karatelabs/karate/tree/master/karate-core#file-upload
and here’s my code:
* configure driver = { type: '#(driverType)', executable: '#(driverExecutable)', addOptions: #(driverOptions), headless: #(driverHeadless), webDriverSession: #(webDriverSession), showDriverLog: true }
Given waitFor('#upload)
And driver.inputFile('#upload', '../assets/pdf-exemple.pdf')
My browser is chrome
what am I missing ?
Thanks for your help
EDIT:
Thank you for your feedback, I’ll try to clarify.
Meanwhile I have some details. In fact the browser is chromedriver and geckodriver
const drivers = {
path: "./src/test/java/drivers/",
chromedriver: "95.0.4638.69",
geckodriver: "0.30.0",
};
So I think I have to use the approach "multipart file".
I tried this code, and my test passes without error, but does not handle the expected functionality (uploading an attachment)
And url 'https://url file file to upload/test' //page where is the area to upload a file
And waitFor(data.inputPJ).click() //area where you click on the application to upload a file
And multipart file file = { read: '../../assets/pdf-exemple.pdf', filename: '../../assets/pdf-exemple.pdf' }
And method post
But in my application this code has no effect, in the application I should have :
But the uploaded file doesn't appear, and I have:
The difficulty here is that I have no mistake. I will continue to try to understand the doc
I am at your disposal to provide more information
I spent the whole day but was unable to find a solution.
I installed CKEditor and KCFinder, everything works fine except for one: when I want to upload a image from the "Browse Server" window file dosen't upload and result is "Unknow error".
When I upload from simple tag "Upload" the file is uploading but is not created a thumb and when I browse the server i can't see the thums of images, only icons of pic and name.
upload:
'uploadURL' => "http://domain.com/uploads/",
'uploadDir' => "../../../uploads/",
config:
CKEDITOR.config.filebrowserBrowseUrl = '<?=$GLOBALS['_st_']['urlTree']?>libraries/kcfinder/browse.php?opener=ckeditor&type=files';
CKEDITOR.config.filebrowserImageBrowseUrl = '<?=$GLOBALS['_st_']['urlTree']?>libraries/kcfinder/browse.php?opener=ckeditor&type=images';
CKEDITOR.config.filebrowserFlashBrowseUrl = '<?=$GLOBALS['_st_']['urlTree']?>libraries/kcfinder/browse.php?opener=ckeditor&type=flash';
CKEDITOR.config.filebrowserUploadUrl = '<?=$GLOBALS['_st_']['urlTree']?>libraries/kcfinder/upload.php?opener=ckeditor&type=files';
CKEDITOR.config.filebrowserImageUploadUrl = '<?=$GLOBALS['_st_']['urlTree']?>libraries/kcfinder/upload.php?opener=ckeditor&type=images';
CKEDITOR.config.filebrowserFlashUploadUrl = '<?=$GLOBALS['_st_']['urlTree']?>libraries/kcfinder/upload.php?opener=ckeditor&type=flash';
when: $GLOBALS['_st_']['urlTree'] is dinamic something like '../' in one or more steps
I have a problem. In my sencha touch application I have list items like .pdf, .png, ... If user taps on one of them file should be download on his mobile device.
How can I do this? I have no idea :-)
Thanks for help.
You can use phonegap file api to download files, If you are using sencha touch 2.3 or above just follow the bellow steps.
Install phonegap in sencha project by executing following command at the project root and this command creates phonegap folder inside project root.
sencha phonegap init
You need to install two phonegap plugins to work with file api by executing two following commands inside phonegap folder.
$ phonegap local plugin add https://git-wip-us.apache.org/repos/asf/cordova-plugin-file.git
$ phonegap local plugin add https://git-wip-us.apache.org/repos/asf/cordova-plugin-file-transfer.git
Now you can start working file api in sencha touch and you can follow below code i used for one of my project.
If you want to download file, first you need to read device file system and then using file system you can download files.
getFileSystem : function(){
var me =this;
Ext.Viewport.mask({
xtype: 'loadmask',
message: 'Downloading files..'
});
var extfs = Ext.create("Ext.device.filesystem.Cordova");
extfs.requestFileSystem({
type: window.PERSISTENT,
size: 1024 * 1024,
success: function(fSys) {
window.fileSys = fSys;
Ext.Viewport.unmask();
me.fileDownload("myfolder/filename.png","http://someurl");
},
failure: function(error){
alert(error);
Ext.Viewport.unmask();
}
});
}
I am passing fileLocation(location you want to store file inside phone) & url in above function.
fileDownload: function(fileLocation,Url){
Ext.Viewport.mask({
xtype: 'loadmask',
message: 'Downloading files..'
});
var me = this;
var fSys = window.fileSys
if(fSys){
var file = Ext.create('Ext.device.filesystem.FileEntry',
fSys.fs.root.toURL() + fileLocation, fSys);
file.download({
source: Url,
success: function(entry){
Ext.Msg.alert('SUCCESS', 'Image successfully downloaded');
Ext.Viewport.unmask();
},
failure: function(error){
Ext.Msg.alert('ERROR', 'Download failed');
Ext.Viewport.unmask();
}
});
}
}
Now can see image at internalMemorycard/myfolder/filename.png
Sencha docs
Ext.device.filesystem.Cordova
Ext.device.filesystem.FileEntry
If you are using sencha touch 2.2 or below only change is instead of using sencha class you need to directly use phonegap api.
For reading file system & File download follow phonegap documentation.
Sencha basically operates over HTML, CSS & JS. Rather than doing this using Sencha just implement it similar to how you would do it in HTML then integrate into your application.
Eg: Homework
Try this
document.location= url;
Try the following code it may help you.
var newWindow = window.open('filepath', '_self'); //were filepath is the path of file with extension.
In my Rails App (3.2.12) I'm using the jquery-fileupload-rails gem to enable users ti upload profile pictures. Everything works fine in Chrome and Safari, but in Internet Explorer (I tested it with version 10) I can't even select files to upload. When I click the 'Add Files'-Button, instead of showing a dialog to select files he instantly fires an empty request to the upload action, resulting in a json response showing an empty photo object. This is my current js to initialize the fileupload (I already added some code from issues with IE and the csrf-tokens):
// Initialize the jQuery File Upload widget:
$('#fileupload').fileupload({
dataType: 'json',
acceptFileTypes: /(\.|\/)(gif|jpe?g|png|tiff)$/i
});
// Enable iframe cross-domain access via redirect option:
$('#fileupload').fileupload(
'option',
'redirect',
window.location.href.replace(/\/[^\/]*$/, '/photos?%s')
);
//add csrf token manually for ie iframe transport
$('#fileupload').bind('fileuploadsend', function(event, data) {
auth_token = $('meta[name="csrf-token"]').attr('content');
data.url = data.url + '?authenticity_token=' + encodeURIComponent(auth_token);
$.blueimp.fileupload.prototype.options.send.call(this, event, data);
});
and my controller code for the response, in which I already (hopefully correct) set the content type to 'text/plain':
format.html {
render json: [#photo.to_jq_upload].to_json,
content_type: 'text/plain', #content_type: 'text/html',
layout: false
}
format.json {
render json: {files: [#photo.to_jq_upload]},
content_type: 'text/plain',
status: :created,
location: #photo
}
Does anyone know, how to get this to work in IE and can help me please? Thanks :)
It took me quite some time to figure it out but in the end it was actually pretty simple: When applying my own styles I replaced the span-tag around the Add-Files-Button with a button-tag. This had no effect in the webkit browsers, however led to an immediate form submit in Firefox and Internet Explorer. Changing it back finally solved the issue :)
- form_for(#post, :remote => true, :id => 'post_form') do |f|
Works as expected in FF and Chrome, but IE just processes the submit action normally, without any ajax request.
Not really seeing any info on this on the rest of the internet so I imagine I've done something wrong somehow. Ive used both the default rails.js, and the jquery version from the github page
Well, I don't know why the default rails version doesn't work for me here on IE, but I wrote this as a workaround:
if ($.browser.msie) {
var form = $('form#new_post');
form.find('input#post_submit').bind('click', function(){
var data = form.serializeArray();
$.ajax({url: '/posts', type: 'POST', data: data});
return false
});
}
And now it's working correctly. Shouldn't something like this be included in rails.js if this is in fact a problem with Rails, and not something that I've somehow done?
In our Rails 3 app the form tagged as data-remote wasn't turned into an AJAX form any longer after we had upgraded to jquery-rails 1.0.19. IE7 wasn't able to load the jquery.js - there seems to be a problem with version 1.7.1 of jQuery currently. After downgrading to jquery-rails 1.0.18 the problem disappeared again.