-
Notifications
You must be signed in to change notification settings - Fork 1
DO NOT MERGE: Upload using URL #6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from 10 commits
20e4d94
c4a016e
cb8e0e5
54707ff
641a7f0
76484d0
52dd082
f181143
ad5044a
6e4c923
a634e44
937123f
af7d607
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,8 +1,15 @@ | ||
| # Upload to SharinPix using URL | ||
|
|
||
| # [Flow](https://github.com/sharinpix/demo-apex/tree/flow) | ||
| Deploy this branch to your Salesforce organization and open the `SharinPixImageFromUrlsDemo` Visualforce page. | ||
| At the top of the page, insert the Album ID in which you wish to upload. | ||
|
|
||
| [<img src="https://raw.githubusercontent.com/afawcett/githubsfdeploy/master/deploy.png">](https://githubsfdeploy.herokuapp.com?owner=sharinpix&repo=demo-apex&ref=flow) | ||
| Fill in the fields. | ||
| * filename - the filename that will be used to store this file. | ||
| * URL - the URL of the image file. | ||
|
|
||
| # Work Order token | ||
| You may add more URLs by clicking on the `Add URL` button. | ||
| Once done, click on `Upload`. | ||
|
|
||
| [<img src="https://raw.githubusercontent.com/afawcett/githubsfdeploy/master/deploy.png">](https://githubsfdeploy.herokuapp.com?owner=sharinpix&repo=demo-apex&ref=work_order_token) | ||
| **Note:** Each URL is sent individually to the Apex controller for upload. (Multiple requests) | ||
|
|
||
| [<img src="https://raw.githubusercontent.com/afawcett/githubsfdeploy/master/deploy.png">](https://githubsfdeploy.herokuapp.com?owner=sharinpix&repo=demo-apex&ref=upload_by_url) | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| public with sharing class SharinPixImageFromUrlsDemo { | ||
|
|
||
| @RemoteAction | ||
| public static Boolean uploadByUrls(String albumId, String url, String filename) { | ||
| sharinpix.Utils utils = new sharinpix.Utils(); | ||
| utils.uploadFromUrl(url, albumId, filename); | ||
| return true; | ||
|
||
| } | ||
|
|
||
|
||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| <?xml version="1.0" encoding="UTF-8"?> | ||
| <ApexClass xmlns="http://soap.sforce.com/2006/04/metadata"> | ||
| <apiVersion>40.0</apiVersion> | ||
| <packageVersions> | ||
|
||
| <majorNumber>1</majorNumber> | ||
| <minorNumber>33</minorNumber> | ||
| <namespace>sharinpix</namespace> | ||
| </packageVersions> | ||
| <status>Active</status> | ||
| </ApexClass> | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,12 @@ | ||
| <?xml version="1.0" encoding="UTF-8"?> | ||
| <Package xmlns="http://soap.sforce.com/2006/04/metadata"> | ||
| <version>36.0</version> | ||
| <types> | ||
| <members>SharinPixImageFromUrlsDemo</members> | ||
| <name>ApexPage</name> | ||
| </types> | ||
| <types> | ||
| <members>SharinPixImageFromUrlsDemo</members> | ||
|
||
| <name>ApexClass</name> | ||
| </types> | ||
| <version>40.0</version> | ||
| </Package> | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,123 @@ | ||
| <apex:page controller="SharinPixImageFromUrlsDemo"> | ||
| <script> | ||
| function generateUrlInput(index) { | ||
| return '<div class="padding-top slds-form-element"><label class="slds-form-element__label">'+ | ||
| 'URL number ' + (index+1) + '</label><div class="slds-grid slds-wrap slds-grid_pull-padded">'+ | ||
| '<div class="slds-p-horizontal_small slds-size_1-of-1 slds-medium-size_1-of-1 slds-large-siz'+ | ||
| 'e_4-of-12"><div class="slds-form-element__control"><input type="text" id="input-filename-' + index + | ||
| '" class="slds-input" placeholder="Filename" /></div></div><div class="slds-p-horizontal_small'+ | ||
| ' slds-size_1-of-1 slds-medium-size_1-of-1 slds-large-size_8-of-12"><div class="slds-form-element_'+ | ||
| '_control"><input type="text" id="input-url-' + (index) + '" class="slds-input" placeholder='+ | ||
| '"URL" /></div></div></div></div>' | ||
|
||
| } | ||
| </script> | ||
| <style> | ||
| #main { | ||
| padding: 10px 20px; | ||
| } | ||
| #main-form { | ||
| max-width: 800px; | ||
| } | ||
| .margined-top { | ||
| margin-top: .5em !important; | ||
| } | ||
| .padding-top { | ||
| padding-top: .5em !important; | ||
| } | ||
| .divider-top { | ||
| border-top: 1px solid rgba(0, 0, 0, .3); | ||
| } | ||
| #success-div { | ||
| display: none; | ||
| position: fixed; | ||
| top: 0; | ||
| right: 0; | ||
| } | ||
| </style> | ||
| <div class="slds-scope" id="main"> | ||
| <div class="slds-grid"> | ||
| <div class="slds-col"> | ||
| <div id="success-div" style="height: 4rem;"> | ||
| <div class="slds-notify_container slds-is-relative"> | ||
| <div class="slds-notify slds-notify_toast slds-theme_success" role="alert"> | ||
| <div class="slds-notify__content"> | ||
| <h2 class="slds-text-heading_small ">Your images was send for upload.</h2> | ||
|
||
| </div> | ||
| </div> | ||
| </div> | ||
| </div> | ||
| </div> | ||
| </div> | ||
| <div class="slds-grid"> | ||
| <div class="slds-col"> | ||
| <div id="main-form" class="slds-form slds-form_stacked"> | ||
| <div class="slds-form-element"> | ||
| <label class="slds-form-element__label" for="input-unique-id">Album ID</label> | ||
| <div class="slds-form-element__control"> | ||
| <input type="text" id="input-album-id" class="slds-input" /> | ||
| </div> | ||
| </div> | ||
| <div class="margined-top" id="urls"> | ||
| <script>document.write(generateUrlInput(0))</script> | ||
| </div> | ||
| <div class="margined-top slds-form-element"> | ||
| <button type="button" onclick="uploadAll()" class="margined-top slds-button slds-button_brand"> | ||
|
||
| Upload | ||
| </button> | ||
| <button type="button" onclick="addUrl()" class="margined-top slds-button slds-button_neutral"> | ||
| Add URL | ||
| </button> | ||
| </div> | ||
| </div> | ||
| </div> | ||
| </div> | ||
| </div> | ||
| <script> | ||
| var isEmpty = function(string) { | ||
| return string === ''; | ||
|
||
| }; | ||
| var addUrl = function() { | ||
| var $urls = document.getElementById('urls'); | ||
| if ($urls.childElementCount <= 10) { | ||
| var values = []; | ||
| for (var index = 1; index < $urls.childElementCount; index++) { | ||
| var filename = document.getElementById('input-filename-' + (index-1)).value; | ||
| var url = document.getElementById('input-url-' + (index-1)).value; | ||
| values.push({filename: filename, url: url}); | ||
| } | ||
| var urlInputHtml = generateUrlInput($urls.childElementCount - 1); | ||
| $urls.innerHTML += urlInputHtml; | ||
| for (var index = 1; index < $urls.childElementCount - 1; index++) { | ||
| document.getElementById('input-filename-' + (index-1)).value = values[index-1].filename; | ||
| document.getElementById('input-url-' + (index-1)).value = values[index-1].url; | ||
| } | ||
| } | ||
| }; | ||
| var uploadAll = function() { | ||
| var $urls = document.getElementById('urls'); | ||
| for (var index = 1; index < $urls.childElementCount; index++) { | ||
| var albumId = document.getElementById('input-album-id').value; | ||
| var filename = document.getElementById('input-filename-' + (index-1)).value; | ||
| var url = document.getElementById('input-url-' + (index-1)).value; | ||
| if (!albumId || !url || !filename || isEmpty(albumId) || isEmpty(url) || isEmpty(filename)) { | ||
| alert('Fill all fields appropriately.'); | ||
| return; | ||
| } | ||
| Visualforce.remoting.Manager.invokeAction( | ||
| '{! $RemoteAction.SharinPixImageFromUrlsDemo.uploadByUrls }', | ||
| albumId, url, filename, | ||
| function(res) { | ||
| if (res) { | ||
| $alert = document.getElementById('success-div'); | ||
| $alert.style.display = 'block'; | ||
| setTimeout(function() { | ||
| $alert.style.display = 'none'; | ||
| }, 4000) | ||
| } | ||
| } | ||
| ) | ||
| } | ||
| } | ||
| </script> | ||
| <apex:slds /> | ||
|
||
| </apex:page> | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| <?xml version="1.0" encoding="UTF-8"?> | ||
| <ApexPage xmlns="http://soap.sforce.com/2006/04/metadata"> | ||
| <apiVersion>40.0</apiVersion> | ||
| <availableInTouch>false</availableInTouch> | ||
| <confirmationTokenRequired>false</confirmationTokenRequired> | ||
| <label>SharinPixImageFromUrlsDemo</label> | ||
| <packageVersions> | ||
| <majorNumber>1</majorNumber> | ||
| <minorNumber>7</minorNumber> | ||
| <namespace>sf_com_apps</namespace> | ||
| </packageVersions> | ||
| <packageVersions> | ||
|
||
| <majorNumber>1</majorNumber> | ||
| <minorNumber>33</minorNumber> | ||
| <namespace>sharinpix</namespace> | ||
| </packageVersions> | ||
| <packageVersions> | ||
| <majorNumber>2</majorNumber> | ||
| <minorNumber>1</minorNumber> | ||
| <namespace>tfa</namespace> | ||
| </packageVersions> | ||
| </ApexPage> | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
README modified - added backticks and markdown syntax instead of html tags
useful link - https://github.com/adam-p/markdown-here/wiki/Markdown-Cheatsheet