Motivation
Most of the time, we, the developers, must have to manipulate large files on the website like videos, audios or other documents. If the unit size of files is small, then its okey. There is no big deal to handle these files of small size. But when the application requires to upload files of large size like 5GB on each upload, we need to consider the reliablity of the upload script. We need to consider the maximum size of files which can be uploaded. We need to consider the maximum bandwidth we can use at a time. We have to take the burden of server optimization.
To get rid of these headache, we can handle this file manipulation tasks to other 3rd party who is already established with the service of file manipulation.
Dropbox is cloud based file hosting server in which users can upload their files and can download when needed. Dropbox has provided lots of features including large file uploading with optimized way.
Dropbox has also provided an api which is highly user-friendly so that any developer can use that.
Objective
To develop a script in which visitors/users of the application can upload file via drag drop or choosing. Instead of the hosting space, these files will be uploaded on dropbox space of the owner of the application. Then these files can be used for different purposes.
Features
1. Multiple files uploading at a time
2. File uploading to owner’s dropbox storage
3. No need to have headache about file manipulation, storage, bandwidth of file uploading.
4. Recrsively finds every files from all folders and uploads to dropbox
Acknowledgements
First of all I would like to thank the Dropbox Team for providing this awesome service.
Then I thank Mr. Nuhil Mehdy (nuhil.net) to give me the idea.
Lets start the development of an simple application called UploaDrop by which end user will upload something to your website, and instead of your host, it will be uploaded on dropbox.
When you are a Developer
The first task is to create an app on your Dropbox account using developer account.
1. Go to https://www.dropbox.com/developers/apps and Click on “Create app” button.
2. Fill these given fields as the picture shows.
3. After completing the creation of your app you will see the details of your app by going https://www.dropbox.com/developers/apps and click on the App Name ‘UploaDrop’.
See the rounded area which provides app key and app secret. These two key defines the access of your dropbox account for uploading from outside.
4. Now open composer.json for editing and set these keys on this like the picture shows.
5. OK, In this step you are all set. Now lets get the access key. Execute getAccesskey.php on the browser which returns a url like
https://www.dropbox.com/1/oauth2/authorize?locale=&client_id=12ab34vd&response_type=code
6. Copy this url and paste on the browser. It will ask for permission to create a folder named app name on the dropbox account.
Click on “Allow”
7. An access key will be displayed like the given screenshot.
Save the Access key on some secured place.
8. Open index.php and and edit the $accesskey field on line 10.
Open processupload.php and do the same task on line 5.
Here, developer’s work is finished. All configuration is finished.
Front End behavior
1. Hit “index.php” on the browser, the front end page will be arrived.
2. In the drag&drop area, user can drag&drop their files and folders. A progress bar will be shown for each of the files when uploading. After completation of uploading of all files click on “Finish Uploading”.
This is the simple app. Actually, It is a brief instruction of how to use Dropbox Core Api.
Future Works
1. In the top area, all existing files are being displayed in recursive structure which is coded by me. In dropbox core api, there are options to create download link of each files, Editing, Deleting etc. These 3 features can be achieved in future.
2. If any compressed file is drop on the drag&drop area, it doesnt extract the compressed file. In future, it can be an issue.
]]>An API (application programming interface) is a term meaning the functions/methods in a library that we can call to ask it to do things for us – the interface to the library.
An SDK ( (software development kit) is a library (often with extra tool applications, data files and sample code) that aid us in developing code that uses a particular system (e.g. extension code for using features of an operating system (Windows SDK), drawing 3D graphics via a particular system (DirectX SDK), writing add-ins to extend other applications (Office SDK), or writing code to make a device like an Arduino or a mobile phone do what we want)
[Collected]
HAPPY NEW YEAR, 2014
]]>sudo nano /etc/apache2/sites-available/default
sample:
ServerAdmin webmaster@localhost DocumentRoot /var/www Options FollowSymLinks AllowOverride All <- HERE Options Indexes FollowSymLinks MultiViews AllowOverride All <- HERE Order allow,deny allow from all ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/ AllowOverride None Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch Order allow,deny Allow from all ErrorLog ${APACHE_LOG_DIR}/error.log # Possible values include: debug, info, notice, warn, error, crit, # alert, emerg. LogLevel warn CustomLog ${APACHE_LOG_DIR}/access.log combined Alias /doc/ "/usr/share/doc/"Options Indexes MultiViews FollowSymLinks AllowOverride None Order deny,allow Deny from all Allow from 127.0.0.0/255.0.0.0 ::1/128
Step 2: Enable module rewrite
command: sudo a2enmod rewrite
Step 3: Restart apache server
command: sudo service apache2 restart
sample .htaccess:
RewriteEngine on RewriteCond $1 !^(index.php|images|robots.txt) RewriteRule ^(.*)$ /index.php/$1 [L]
N.B: Don’t forget to press Enter once at the end of the htaccess file.Because Newline represents the end of file.
SELF NOTE
]]>Code Written in JAVA
/* * To change this template, choose Tools | Templates * and open the template in the editor. */ import java.io.BufferedWriter; import java.io.FileWriter; import java.io.IOException; import java.io.*; import java.sql.*; import java.util.logging.Level; import java.util.logging.Logger; /** * * @author Ujjal Suttra Dhar */ class create_backup{ String database = "your_database_name", user = "root", password = "pass"; Connection m_Connection = null; Statement m_Statement = null; ResultSet m_ResultSet; String m_Driver = "com.mysql.jdbc.Driver"; String m_Url = "jdbc:mysql://localhost:3306/" + database; public create_backup(){ /*Eshtablishment of Connection of java code with MySQL using JDBC You must read my previous post to know further about this. */ try { Class.forName(m_Driver); m_Connection = DriverManager.getConnection(m_Url, user, password); //Create Statement object m_Statement = m_Connection.createStatement(); } catch (Exception ex) { ex.printStackTrace(); } try { //Database will be stored in filename.sql which can be import on MySQl as backup BufferedWriter out = new BufferedWriter(new FileWriter("kernel_school.sql")); //Now here is the informations about the database of which backup will be created String dump = "C:/Program Files/MySQL/MySQL Server 5.0/bin/mysqldump " //Path to mysql + "--host=localhost" //Mysql hostname + "--port=3306" //Mysql portnumber + "--user=root" //Mysql username + "--password=pass" //Mysql password + "--add-drop-table" //Add a DROP TABLE statement before each CREATE TABLE statement + "--add-drop-database" //Add a DROP DATABASE statement before each CREATE DATABASE statement + "--complete-insert" //Use complete INSERT statements that include column names. + "--extended-insert" //Use multiple-row INSERT syntax that include several VALUES lists + "kernel_school"; //Mysql databasename //executing the command through process. Process run = Runtime.getRuntime().exec(dump); /*resultant SQL informations are here on the br which can be read line by line . And at the same time it will be written on another sql file.*/ InputStream in = run.getInputStream(); InputStreamReader isr = new InputStreamReader(in); BufferedReader br = new BufferedReader(isr); String line = null; while ((line = br.readLine())!=null) { out.write(line); out.newLine(); } out.flush(); // must flush or close the file after completing the task. // int exitVal = run.waitFor();//when exitVal is ,then the process is completed } catch (Throwable t) { t.printStackTrace(); } }//constructor } // class public class autobackup { public static void main(String a[]){ new create_backup(); } }
Code Written in PHP
]]>