I am currently trying to use filepicker on my Meteor project. I have been able to successfully show the pick a file button via front end, click, load the filepicker widget and upload a file. I am using the free storage with 5000 images. Filpicker confirms I have uploaded 30 files already. I am not sure how to get the URL and store it on my mongo DB. I am very new to development. I am using Coffee script. This is what I have:
Initializing:
Template.MyTemplate.rendered = () ->
filepicker.setKey("AouIUs8H6RnuPwHB5gqOyz")
filepicker.constructWidget(document.getElementById('attachment'))
Event Handler:
Template.MyTemplate.events
'change #attachment': () ->
console.log "attachment changed"
HTML
<div class="dataEntry">
Your File <input type="filepicker" id="attachment"/>
</div>
Not sure how to see the returned URL for the file and how to store it. I would much appreciate your support. As I mentioned I am new to this so if possible when in doubt don't assume I know. Thanks! - M
Related
I have a method which prints a pdf report and downloads it to the OS in Odoo 13 upon clicking a button. Now, I need to get (access) the path (where it is downloaded) of this report (file) and store it in ir_attachment table of Odoo. After storing the file (report) path then I want to have a button which fetch this report from it's the path stored in database and shows it in browser for a portal user in website module. I searched a lot but could not find anyway to do it. Can anyone help me if is it possible and if yes how?
Have you check with this method get_portal_url(report_type='pdf', download=True)?
I am having a small issue using Odoo,
I have more then 1000 file to upload into Odoo V11 (.pdf/.stp), each file in attached to a P/N, I managed to have the adresse link for every par number created in odoo, but still i dont know how to make a bulk upload,
Now i am trying to create a macro for upload file per file but i am stuck in the first part.
I never used JavaScript before :/
here is the the main page of the PN :11050-1-A
when i lunch chrome console to click automatically in "ajouter" (Add) with
var el = document.getElementsByClassName('input_file_XXXX');
el[0].click();
i got a files dialogbox
lets say that the file is stored in desktop and called "11050-1-A - Test.pdf"
How can I automatically select the file?
Do you have another idea to solve this problem ?
If you have let's say more than 100 of these that needs to be imported once, you will need to create a Python script that uses Odoo's XML-RPC to upload the files. The process will be:
Connect to the XML-RPC and authenticate
Search for a product with the name
Search for the file on your computer
Create a new ir.attachment that links to the product
XML-RPC link: https://www.odoo.com/documentation/12.0/webservices/odoo.html
I'm currently using CKEditor in my site. The user may upload some images to the server using the button for Upload Image in the CKEditor.
There is a textarea field with id #article_conteudo on the page that uses the CKEditor, here is the javascript code to configure the editor:
CKEDITOR.replace('article_conteudo', {
filebrowserImageUploadUrl: '/article/upload/'
});
The URL /article/upload/ points to a method file_upload in an articles_controller:
def file_upload
image = ArticlesImage.new
image.imagem = params[:upload].read
image.save
end
The images are stored in a BLOB field in a MySQL Database.
The images are saved in the database with no problems. But, after saving, nothing happens in the Editor. I'm not sure what is the expected response for the Upload Action of the CKEditor on this case. I'm not sure, also, if CKEditor uploads support the use of BLOBs.
How can I implement this functionality in my project?
If it can't be done with CKEditor, is there any other plugin that can do it?
Thanks for your help
PS: The use of BLOB is MANDATORY for the project, I cannot use other methods
it depends of what you need.
If you want to display images on your browser, you have to create the JSON response involved.
And then, the fileUploadResponse of the CKEditor would be able to display your images (or files) on your editor.
I am using angular and ASP.NET Web API to allow users to download files that are generated on the server.
HTML Markup for download link:
<img src="/content/images/table_excel.png">
<a ng-click="exportToExcel(report.Id)">Excel Model</a>
<a id="report_{{report.Id}}" target="_self"></a>
The last anchor tag is there to serve as a place holder for an automatic click event. The visible anchor calls the exportToExcel method to initiate the call to the server and begin creating the file.
$scope.exportToExcel = function(reportId) {
reportService.excelExport(reportId, function (result) {
var url = "/files/report_" + reportId + "/" + result.data.Model.fileName;
var dLink = document.getElementById("report_" + reportId);
dLink.href = url;
dLink.setAttribute('download', result.data.Model.fileName);
dLink.click();
});
}
The Web API code creates an Excel file. The file, on the server is about 279k, but when it is downloaded on the client it is only 7k. My first thought was that the automatic click might be happening before the file is completely written. So, I added a 10 second $timeout around the click event as a test. It failed with the same result.
This seems to only be happening on our remote QA server. On my local development server I always get the entire file back. I am at a loss as to why this might be happening. We have similar functionality where files are constructed from a database blob and saved to the local disk for download. The same method is employed for the client side download and that seems to work fine. I am wondering if anyone else has run into a similar issue.
Update
After the comment by SilentTremmor we think it actually may be IIS or some sort of Sever issue. Originally, we didn't think it could be, but after some digging it may be. It seems the instance of the client code is only allowing 7k of data to be downloaded. It doesn't matter what we try to download the result is always the same.
It turns out the API application was writing the file to a different instance of our application. The client code had no idea and was trying to download a file that did not exist. So, when the download link was creating the file it was empty, thus the small file size.
I have a file structure on a web page, and look for a solution for the following scenario:
The chosen file should be downloaded in browser cache and opened (if it's an excel document, open with excel, etc.).
Now when the user changes the file, it should be detected and the file should be uploaded again.
Is this even possible with JavaScript?
If yes, where do I store the file (temporary internet folder?) and how do I detect the changes?
The only way for this to work you would need to have the user select the downloaded file, and then check for modification.
HTML
<label for="excelFile">Select the excel file: </label><input type="file" id="excelFile" />
JS
//Change event to detect when the user has selected a file
document.querySelector("#excelFile").addEventListener("change",function(e){
//get the selected file
var file = this.files[0];
//get the last modified date
var lastModified = file.lastModified;
//check lastModified against stored lastModified
//this assumes you store the last mod in localStorage
if(localStorage['excelLastMod'] < lastModified){
//It has modified update last mod
localStorage['excelLastMod'] = lastModified;
//do upload
}
});
If you know your user is using Chrome you can use Chrome's FileSystem api
The way you describe it: No, that is not possible in JavaScript.
It sounds like you want an FTP client.
When the user changes the file, it should be detected and the file should be uploaded again.
That is not possible due to JS having almost no access to the file system.
The only way you can access a file at all is by requesting the user to select one, see:
How to open a local disk file with Javascript?
So the most you could do would be:
File is downloaded.
Based on browser & settings, file may be opened automatically, or not.
User is presented with a file selection dialog that they can use when they are done editing.
Compare selected file to file on server and upload if changed.
After downloading a file, you have no control over it.
For applications that have a protocol registered (such a steam://, for example), you might be able to request the URL being opened in a program, but that would require an if per file type/program.
Detecting file changes is not at all possible (because you have no access to the file), and uploading again requires the user to select the file manually, using a file dialog.
Thanks for your help and ideas. I saw a software (https://www.group-office.com/) which includes this function so there has to be way to do it.
New Idea, using chrome filesystem api (#Siguza already said it):
Create file from servers database on users local filesystem with filesystem api
open file locally (should work with filesystem:http://www.example.com/persistent/info.txt, or?)
poll last changes of file every x seconds
if change detected, upload file back to servers database
I saw some problems with excel locking the files Check if file has changed using HTML5 File API
but except of that this should work, shouldn't it?