I want to make an app that lets a user upload a file to dropbox and then get options to share that file. How can I get a dropbox link for a file? It seems like I could use
client.sharing.createSharedLink(path:"/myfile")
but how would I access that data as a String?
Here's a sample of how you could use createSharedLink in SwiftyDropbox to get a shared link to a file, in this example at the path /test.txt.
Dropbox.authorizedClient!.sharing.createSharedLink(path: "/test.txt").response({ response, error in
if let link = response {
print(link.url)
} else {
print(error!)
}
})
Building on #Greg's answer, you can simply replace www.dropbox.com with dl.dropboxusercontent.com and dl=0 with dl=1 to get the direct share link.
Related
My web app generates a UUIDv4 for every new 'post', and each post has its own URL like /posts/<uuid>. I'm not able to predict what uuid gets generated, and therefore I'm unable to go back to a specific post that was created earlier during testing.
According to the docs, cy.url() returns the URL as a string. I tried saving the URL using a .as(), but it didn't work:
cy.url().as('postUrl');
// go somewhere else
cy.visit('#postUrl');
// ends up visiting `localhost:3000/#postUrl`
I saw in another SO question that I should use .then on cy.url(), but that didn't work either:
cy.url().then(url => url).as('postUrl');
// go somewhere else
cy.visit('#postUrl');
How do I save the current URL for use later?
Found the answer buried in later pages of a google search. In order to use the saved URL, use cy.get('#postUrl') and call a .then with a callback that visits that url.
cy.url().as('postUrl');
// go somewhere else
cy.get('#postUrl').then(url => {
cy.visit(url);
}
var currentUrl=''
cy.url().then(url => {
currentUrl = url;
});
cy.visit(currentUrl)
I'm trying to find the way to parse image from instagram post by link with no login in to instagram.
For now I tried to use Kanna but my xpath request dont work.
I have this code:
import Kanna
func getparse(){
if let doc = try? Kanna.HTML(url: URL(string: "https://www.instagram.com/p/CL19xB_M7Wv/")!, encoding: .utf8){
print(doc.title)
for link in doc.xpath(#"//*[#id="react-root"]/section/main/div/div[1]/article/div[2]/div/div/div[1]/div[1]/img/#src"#) {
print(link.text)
}
}
}
How can I parse it correctly and maybe I can use cocoapod or something?
I guess you copied the xpath from chrome. The DOM presented in the browser gets modified, thats why the xpath query fails.
Use a tool like postman to see the actual structure of the response from your request.
Try something like:
doc?.at_xpath(#"/html/head/meta[#property='og:image']"#)?["content"]
The image url is the "content" attribute of the meta tag with the attribute property set to 'og:image'.
I am trying to populate my collection view with images from the dropbox.
I want to have the thumbnail image for my grid view (collection view) with the following code.
DropboxClientsManager.authorizedClient?.files.getThumbnail(path: filename).response(completionHandler: { (
response, error) in
print(response)
print(error)
})
I get the following error:
Optional([request-id e70dba3b7ee8f0b9bf6b0aa4b19325f0] API route error - {
".tag" = path;
path = {
".tag" = "not_found";
};
})
But when I try to getthumbnail using this following method I get error .I don't know which url i should return to this function:
DropboxClientsManager.authorizedClient?.files.getThumbnail(path: filename, format: .png, size: .w32h32, overwrite: true, destination: { (url, res) -> URL in
print(url)
print(res)
return url
})
UPDATE:
CAN'T WE GET THUMBNAIL URL FOR DROPBOX IMAGES IN IOS?
Does anyone has the solution ?
Any suggestions??
If you want to get a thumbnail for a file in Dropbox using the API v2 Swift SDK, using one of the getThumbnail methods is the correct approach.
For getThumbnail(path:format:size:overwrite:destination:), note that this will write the thumbnail data to the URL you specify. (I.e., it doesn't provide an Internet-accessible URL where the thumbnail data is hosted.)
The getThumbnail(path:format:size:overwrite:destination:) method is a download-style request, so you should use it as shown under "Download-style request" in the readme, per the "Download to URL" example.
The getThumbnail(path:format:size:) method will return the thumbnail data in memory. You would use it as shown under "Download-style request" in the readme, per the "Download to Data" example.
In either case, note that the path/not_found error you're getting is referring to the path: filename parameter you're supplying. That is, there is nothing found at that path in the Dropbox account. You should specify the remote Dropbox path of the file that you want a thumbnail for.
We can get the share link for a dropbox folder from SDK(https://github.com/dropbox/dropbox-sdk-ruby/blob/master/lib/dropbox_sdk.rb#L1222-L1225), which link is dl=0 by default, I need to set it with dl=1 so that it will download directly, I did some hack:
require 'dropbox_sdk';
client = DropboxClient.new(ENV['dropbox_access_token'])
session = DropboxOAuth2Session.new(Option['dropbox_access_token'], nil)
response = session.do_get "/shares/auto#{client.format_path('/auction_offerings/two')}", {"short_url" => false}
response = Dropbox::parse_response(response)
response["url"][-1]="1"
Then response["url"] will become the download link I want, but it is obvious not the right way to do that. Any better practice?
I created a configuration file (Simple Text File) on my Google Drive and now I would like to read it from my Chrome Packaged Dart Application. But I'm not able to get more information of the file than it's name, size etc.
For accessing Google Drive I use the google_drive_v2_api.
Any suggestion on how to get the contents of my configuration file would be great! Thanks!
I just did some test in my own chrome app, uploading and downloading a simple file:
chrome.identity.getAuthToken(new chrome.TokenDetails(interactive: true ))
.then((token){
OAuth2 auth = new SimpleOAuth2(token);
var drive = new gdrive.Drive(auth)..makeAuthRequests=true;
drive.files.insert({},content:window.btoa('hello drive!')).then((sentMeta){
print("File sent! Now retrieving...");
drive.files.get(sentMeta.id).then((repliedMeta){
HttpRequest request = new HttpRequest()..open('GET', repliedMeta.downloadUrl)
..onLoad.listen((r)=>print('here is the result:'+r.target.responseText));
auth.authenticate(request).then((oAuthReq)=>oAuthReq.send());
});
});
});
It works, but the HttpRequest to get content back seems heavy...
But i really recommend you to a take look to chrome.storage.sync if your config file size is < to 4ko... If not, you could also use the chrome SyncFileSystem API... They are both easier to use, and SyncFileSystem use Drive as backend.
This page on downloading files talks through the process for getting the contents of a file.