govwiki / govwiki-dev.us

Development Branch of govwiki.us
http://govwiki.github.io/govwiki-dev.us/
1 stars 2 forks source link

Create script to upload PDF files to DreamFactory #29

Open joffemd opened 9 years ago

joffemd commented 9 years ago

I need to upload a large number of PDF files to a folder on Dreamfactory so that the files can be served by the application. Unfortunately, Dreamfactory has a very bad upload user interface and poor documentation for using its file services. I tried creating the Python script below, but got an error message saying ": "POST access to component 'pdfs' of service 'files' is not allowed by this user's role."

I get this despite initializing a session id.

If you can suggest any alternative free or low cost file serving solution, that would also be welcome. Dropbox and Google Drive cannot be used for this purpose because individual links must be generated for each file.

Python script:

!/usr/bin/env python

-- coding: utf-8 --

import json import requests

start_session_url = "http://46.101.3.79:80/rest/user/session?app_name=govwiki" payload = {'email': 'marc@publicsectorcredit.org' , 'password': 'pscs@2O12'}

print json.dumps(payload)

s = requests.post(start_session_url, data=json.dumps(payload))

print sess_resp = s.text print sess_resp print print len(sess_resp) print

session_id_pos = sess_resp.find("session_id") bgn_pos = sess_resp.find(chr(34), session_id_pos + 11) + 1 end_pos = sess_resp.find(chr(34), bgn_pos + 5) session_id = sess_resp[bgn_pos:end_pos]

print session_id_pos print bgn_pos print end_pos print session_id print

audit_year = "2014" govt = "Concord" url = "http://46.101.3.79:80/rest/files/pdfs/General%20Purpose/CA%20" + govt + "%20" + audit_year + ".pdf?check_exist=false&app_name=govwiki&X-DreamFactory-Session-Token=" + session_id

files = {'file': open("D:\Dropbox (PSCS)\CA_Audits\General Purpose\CA " + govt + " " + audit_year + ".pdf", 'rb')}

print url

r = requests.post(url, files=files)

print r.text

print r

joffemd commented 9 years ago

This issue is deprioritized. I am using GoDaddy rather than DreamFactory to serve the files. Performance on the GoDaddy server is slow, so we may need to review this issue again in the future.

vadim-ivlev commented 9 years ago

In my view an easier solution is to copy files over SSH to 46.101.3.79.

The files are stored in: /opt/dreamfactory-1.9.1-1/apps/dreamfactory/htdocs/storage/pdfs/ folder on the server.

Instead of writing scripts we can use scp or rsync commands to copy files or folders from local computers to 46.101.3.79.