Presented by Alexey Vedishchev Developing Web-applications with Grails framework American University of Nigeria, 2016 Uploading and Downloading Files.

Slides:



Advertisements
Similar presentations
Visit the ccScan Website Scan, Import, and Automatically File documents to the Cloud SCAN, IMPORT, AND AUTOMATICALLY FILE DOCUMENTS TO SALESFORCE ® Introduction.
Advertisements

Samsung Smart TV is a web-based application running on an application engine installed on digital TVs connected to the Internet.
With Folder HelpDesk for Outlook, support centres and other helpdesks can work efficiently with support cases inside Microsoft Outlook. The support tickets.
A Toolbox for Blackboard Tim Roberts
The Librarian Web Page Carol Wolf CS396X. Create new controller  To create a new controller that can manage more than just books, type ruby script/generate.
OpenCMS and the MSASS Website. A Note on Terminology Locking a file for editing: No lockNOT locked You have write/edit access Someone else has write.
SOFTWARE PRESENTATION ODMS (OPEN SOURCE DOCUMENT MANAGEMENT SYSTEM)
PayDox applications All features can be used independently.
XP Tutorial 9 New Perspectives on JavaScript, Comprehensive1 Working with Cookies Managing Data in a Web Site Using JavaScript Cookies.
Chapter Accreditation Online System Usage Tutorial Department of Member Relations & Grants National Children’s Alliance.
Working with SharePoint Document Libraries. What are document libraries? Document libraries are collections of files that you can share with team members.
Form Handling, Validation and Functions. Form Handling Forms are a graphical user interfaces (GUIs) that enables the interaction between users and servers.
8 Chapter Eight Server-side Scripts. 8 Chapter Objectives Create dynamic Web pages that retrieve and display database data using Active Server Pages Process.
 First time student activates their google account, they need to go to an internet browser and go to  drive.google.com/a/students.macon.k12.nc.usdrive.google.com/a/students.macon.k12.nc.us.
Server-side Scripting Powering the webs favourite services.
Developing Workflows with SharePoint Designer David Coe Application Development Consultant Microsoft Corporation.
© 2003 By Default! A Free sample background from Slide 1 Week 2  Free PHP Hosting Setup  PHP Backend  Backend Security 
SOML Issue Tracking Guide to using the new ETSEDMS server for Issue Tracking.
LiveCycle Data Services Introduction Part 2. Part 2? This is the second in our series on LiveCycle Data Services. If you missed our first presentation,
Open the Goodyear Homepage Click on Teacher Tools.
By: Saurabh Dixit.  Groovy server pages  Taglibs  Validators in grails.
Go to your school’s web locker site school name.schoolweblockers.com) Your user name is the first letter of your first name, the first four.
Unit 3 Day 6 FOCS – Web Design. Journal Unit #3 Entry #4 Write the source code that would make the following display on a rendered page: Shopping List.
1. Profile settings 2. Messaging system 3. Downloading files 4. Uploading files 5. Creating groups 6. Calendar events.
My Documents MarysWebpage 1-WebpageFolders&Files Projects&Assignments MySpinPage SciFairProjPage The folders you should have in “My Documents” are shown.
Go to your school’s web locker site school name.schoolweblockers.com) Your user name is the first letter of your first name, the first 4.
Basic Instructions on how to use One Drive and share files. ONE Drive Your LogoYour own footer.
HTML, Third Edition--Illustrated Introductory 1 HTML, Third Edition Illustrated Introductory Unit G Using Forms to Control Input.
An Introduction to Designing and Executing Workflows with Taverna Aleksandra Pawlik materials by: Katy Wolstencroft University of Manchester.
Go to your school’s web locker site Your user name is the first letter of your first name, the first four letters of.
XRX Basic CRUDS Create, Read, Update and Delete and Search XML Data Date: May 2011 Dan McCreary President Dan McCreary & Associates
SOML Large Optics Daily Reporting Guide to using the new ETSEDMS server for Large Optics Daily Reporting.
Knowledge Management Platform Communities of Practice User Guide for CoP users Copyright © 2010 Group Technology Solutions. All Rights Reserved.
Advanced Web 2012 Lecture 6 Sean Costain Files Sean Costain 2012 Php allows for the : Creation Reading Appending Deleting Uploading And Closing.
A brief introduction to doxygen. What does a compiler do?  A compiler ignores comments and processes the code.  What does doxygen do? –It ignores the.
8 Chapter Eight Server-side Scripts. 8 Chapter Objectives Create dynamic Web pages that retrieve and display database data using Active Server Pages Process.
>> PHP: File Uploads. Pre-requisite Go Online – Download file modify-item.php – copy it to your root folder (D:\xampp\htdocs\Buy4mMe) Web-Based Systems.
Updating to X6 Mike DeButts. Updating to X6 How to Install X6 What Not to do when Updating to X6 Migration Utility New File Locations introduced in X6.
1 More About HTML Images and Links. 22 Objectives You will be able to Include images in your HTML page. Create links to other pages on your HTML page.
PMO Advisors, LLC PMO Advisor © Release 2.1. The PMO Advisor Portal The PMO Advisor is a gateway to Project Management tools. This portal has two primary.
Upload ASN (Indy) in New Website ( Upload ASN (Indy) in New Website (Advanced Shipping Notice)
Instructional/6-8/General Session 1 of 1 Get Going with eChalk Digital File Locker.
V 0.1Slide 1  send – Send How to send in WebSAMS? Access Control Other Information Configuration Customization  manage.
XP New Perspectives on Macromedia Dreamweaver MX 2004 Tutorial 5 1 Adding Shared Site Elements.
© CGI Group Inc. User Guide Subversion client TortoiseSVN.
111 State Management Beginning ASP.NET in C# and VB Chapter 4 Pages
Presented by Alexey Vedishchev Developing Web-applications with Grails framework American University of Nigeria, 2016 Form Submission And Saving Data To.
Emdeon Office Batch Management Services This document provides detailed information on Batch Import Services and other Batch features.
Visual Basic.NET Comprehensive Concepts and Techniques Chapter 11 Creating Web Applications and Writing Data to a Database.
5.5 Adding Photo Gallery Module
Presenter: Chris Blake, Associate Director
Developing Web-applications with Grails framework
CARA 3.10 Major New Features
CONTENT MANAGEMENT SYSTEM CSIR-NISCAIR, New Delhi
Administrator Training
Course Topics Course Topics ECARS Enhancements
How Can I Download My Transactions Directly Into Quicken
Title: Unified Communication Application Suite Keycode Retrieval System (KRS) User Guide Issue: 0.2 Date: July 2011 Hi and welcome to the.
City Selection Entry Form Guide
User Guide Subversion client TortoiseSVN
Title: Agile Communication Environment Keycode Retrieval System (KRS) User Guide Issue: 0.4 Date: July 2011 Hi and welcome to the Order.
About Everything You Always Wanted to Know
How to retrieve CORs from any NeT program in CDX
Microsoft PowerPoint 2007 – Unit 2
This presentation document has been prepared by Vault Intelligence Limited (“Vault") and is intended for off line demonstration, presentation and educational.
Training & Development
MVC Controllers.
MIS 3200 – Unit 6.1 Moving between pages by redirecting
This presentation document has been prepared by Vault Intelligence Limited (“Vault") and is intended for off line demonstration, presentation and educational.
Presentation transcript:

Presented by Alexey Vedishchev Developing Web-applications with Grails framework American University of Nigeria, 2016 Uploading and Downloading Files

This is an example application that implements a simple document management system. The goal is to show how to upload or download documents in a Grails application. Task Description 2

The user can view list of documents: Task Description 3

The user can view list of documents: Clicking an item will download the document file. Task Description 4

There is a form to upload and add a document to the repository: Clicking “Upload” will save the document file into predefined folder. Task Description 5

As this is just a sample application, there is only one domain in the application to represent a document: package com.dms class Document { String filename String fullPath Date uploadDate = new Date() static constraints = { filename(blank:false,nullable:false) fullPath(blank:false,nullable:false) } The filename is to preserve the original filename uploaded by the user. The fullPath is where the document is saved after upload. The uploadDate is just for keeping track of the date and time the document is uploaded. Solution. Step 1: Domain 6

1.Run grails generate-controller com.dms.Document 2.Open DocumentController.groovy. Do not delete existing actions. 3. Update your class DocumentController adding new action list() as shown below. 4.Modify index() action as shown below. class DocumentController { def list() { params.max = 10 [documentInstanceList: Document.list(params), documentInstanceTotal: Document.count()] } def index(Integer max) { redirect (action: "list", params: params) } } Solution. Step 2: Controller 7

10 records per page will be shown : list.gsp Note the entry with: ${documentInstance.filen ame} This is the link to download the file given the document id. Solution. Step 3: View 8

We can configure where to upload the documents by introducing the configuration variable uploadFolder in Config.groovy. We can have different values depending on the environment. 1. Create new empty folder C:\dms\upload 2. Append the following at the bottom of Config.groovy: environments { development { uploadFolder = "c:/dms/upload/" } test { uploadFolder = "c:/dms/upload/" } production { uploadFolder = "c:/dms/upload/" } Solution. Step 4: Configuring upload location 9

Document upload is simple. For the form, we can use the tag uploadForm. create.gsp Solution. Step 4: Document Upload 10

Update your DocumentController.groovy by adding the upload() action, do not delete existing code. The code will be explained in the next slide: def upload() { def file = request.getFile('file') if(file.empty) { flash.message = "File cannot be empty" } else { def documentInstance = new Document() documentInstance.filename = file.originalFilename documentInstance.fullPath = grailsApplication.config.uploadFolder + documentInstance.filename file.transferTo(new File(documentInstance.fullPath)) documentInstance.save() } redirect (action:'list') } Solution. Step 5: Adding upload() action to DocumentController 11

We can access the uploadFolder we set in Config.groovy using the code grailsApplication.config.uploadFolder. The file uploaded can be accessed through request.getFile('file'). The following properties/methods were used: file.empty - check if there is really an uploaded file file.originalFilename - the filename of the document uploaded file.transferTo - transfer the file to a new path. Solution. Step 5: Adding upload() action to DocumentController (explanation) 12

For downloading, we just need to retrieve the file from the file system and send it to the response. Update your Document Controller with download() action (do not delete existing code): def download(long id) { Document documentInstance = Document.get(id) if ( documentInstance == null) { flash.message = "Document not found." redirect (action:'list') } else { response.setContentType("APPLICATION/OCTET-STREAM") response.setHeader("Content-Disposition", "Attachment;Filename=\"${documentInstance.filename}\"") def file = new File(documentInstance.fullPath) def fileInputStream = new FileInputStream(file) def outputStream = response.getOutputStream() byte[] buffer = new byte[4096]; int len; while ((len = fileInputStream.read(buffer)) > 0) { outputStream.write(buffer, 0, len); } outputStream.flush() outputStream.close() fileInputStream.close() } Solution. Step 6: Document Download 13

The calls to response.setContentType("APPLICATION/OCTET- STREAM") and response.setHeader("Content- Disposition", "Attachment;Filename=\"${documentInstance.filena me}\"") are necessary to force the browser to download. Otherwise the browser will try to render the document. The rest of the code is just to read the file and send it to the response object. Solution. Step 6: Document Download (explaining the code) 14

The above code is just to serve as a working example on how to code uploading and downloading of files. To help start projects that needs such feature. Remarks 15