Uploading and serving media files from google drive on django - python

I'm working on an app in django that allows users to upload documents to google drive and share them with friends. The problem is I want to restrict the shared documents to view only (no download option). How can I go about doing this?

You can insert/upload files using the Drive API and set the "restricted" label to prevent downloading of the file. You would then set the appropriate permissions to this file to allow anyone or a specified set of users to access the file.
Download restrictions may or may not apply for files that are converted to one of the Google Apps formats because the option to prevent downloading seems unavailable for these files through the Google Drive UI. You would have to test this yourself.

Related

Unable to render aspx files when uploaded to SharePoint programmatically

I am new to SharePoint. I have written a simple python script that basically connects to SharePoint and uploads files (aspx and other frontend files) from a folder on my local machine to a specific folder on SharePoint site.
To facilitate the script to communicate with the SharePoint, I have a created an App principal under SharePoint using the SharePoint App-Only model. I have done this by calling the appregnew.aspx, example: https://spo.test.com/sites/MYSITE/\_layouts/15/appregnew.aspx , below is the sample page when 'appregnew.aspx' is called
Then, I have provided the below permissions to the App principal through 'appinv.aspx', example - https://spo.test.com/sites/MYSITE/\_layouts/15/appinv.aspx
<AppPermissionRequests AllowAppOnlyPolicy="true">
<AppPermissionRequest Scope="http://sharepoint/content/sitecollection/web" Right="FullControl"/>
</AppPermissionRequests>
Next, I use the Client ID and Client Secret under the Python script to establish communication with SharePoint and to upload files to a specific folder (folder already exists and is not created by the program) on SharePoint, example path to which files are uploaded: https://spo.test.com/sites/MYSITE/Shared%20Documents/TeamDocs2
Note: This script uses Python library 'Office365-REST-Python-Client' to communicate with SharePoint
The script can successfully authenticate itself and also upload the files to the folder on SharePoint. But then when I manually go to the SharePoint folder and click on the aspx file, example : index.aspx; the file gets downloaded instead of getting rendered.
There is no issue with the file i.e. it is not corrupted because when I manually upload the same file onto the same folder, then there is no issue, the file gets rendered.
In regards to the permissions for the App principal, I've already given 'FullControl' at the scope 'sitecolletion/web' level. I also tried changing the scope from 'http://sharepoint/content/sitecollection/web' to 'http://sharepoint/content/sitecollection', this didn't work as well
Please can somebody help me with this. Thanks in advance
The reason the .aspx page is being downloaded is related to security risk mitigation in SharePoint. If you consider that Javascript (.js) files and .aspx files are executable files in the browser, then it should also be self evident that allowing users to upload such files to SharePoint could pose risk. Because of this, Microsoft has disabled custom script on all modern sites by default. You can choose to overrule this setting, but it should be done with extreme caution.

Python and Dropbox: How to change SmartSync setting for locally created files?

I have a working Python script that generates and saves hi-res image files to a local Dropbox folder (synced through the Windows Dropbox app). Is there a way in Python to change the SmartSync setting for the newly created image from "Local" to "Online Only" so that I can save space on my local hard drive? I know I could use the Dropbox API v2 to just upload the file and then delete the temporary local files after, but I'm wondering if there is a way to directly change the file settings since it already gets saved to the synced Dropbox folder.
Thanks!
No, unfortunately Dropbox doesn't offer an API for managing Smart Sync settings like this, but I'll pass this along as a feature request.

How can i automate a spreadsheet which is stored in google drive without downloading it

How can i automate a spreadsheet which is stored in google drive without downloading it.
https://automatetheboringstuff.com/chapter12/
If you have Read permission on a folder (called View permission on Google Drive), you can open and run code from a workbook stored there, however technically the file is still being downloaded to your local machine, likely in a temporary folder.
If you have Write permission on a folder (called Edit permission on Google Drive), you can replace/overwrite a file that's stored there.
View: People can view, but can’t change or share the file with others.
Comment: People can make comments and suggestions, but can’t change or share the file with others.
Edit: People can make changes, accept or reject suggestions, and share the file with others.
More Information :
Google Support : Share files from Google Drive
Microsoft.com : Windows Temporary Files

How do I work on multiple appengine projects with python?

I need to export my blobstore from one appengine project and upload it to another project. How can I switch between projects programmatically with python?
If by "python" you mean a python GAE app's code itself - AFAIK you can't switch apps - each such code runs only inside the app specified in the .yaml file.
You could teach the exporting app project to serve the blob and for the actual transfer you could either:
have the receving app directly pulling the blobs from the exporting app
have an external (python) script pull blobs from the exporting apps and uploading them to the importing app.
Either way you'd need to write some code to actually perform the transfer.
So instead of doing that, I'd rather write and execute a one-time conversion script to move the data from blobstore (presently shown in the GAE python docs under Storing Data > Superseded Storage Solutions section on the left-side menubar) to the Datastore or GCS, both of which have better backup/restore options, including across apps :) GCS can probably be even used to share the same data across apps. And you can still serve the GCS data using the blobstore API, see Uploading files directly to Google Cloud Storage for GAE app
If you mean some external python app code - AFAIK the blobstore doesn't offer generic access directly to an external application (I might be wrong, tho). So an external app would need to go through the regular upload/download handlers of the 2 apps. So in this case switching between projects really means switching between the 2 apps' upload/download URLs.
Even for this scenario it might be worthy to migrate to GCS, which does offer direct access, see Sharing and Collaboration

how to allow my own google drive app to only upload files

I want to develop a backup app, I wish that the app will be able only to upload files without any permissions to delete files (or any other permission).
is it possible ?
Yes, it's possible. Start by looking for a python library that lets you communicate with the Google Drive API. See Google APIs Client Library and PyDrive (you'll find easy code as example here).

Categories