You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
If you can't use CDN enabled containers, you can use the Temp URL functionality to create special URLs which grant an anonymous user access to a file. In the example below, a URL is generated which grants read access for 1 day.
Note that your account must have a Temp-URL-Key account metadata value set first. This value should be set once, and then reused. Changing the Temp-URL-Key will invalidate previously generated temp URLs.
usingSystem;usingSystem.Collections.Generic;usingJSIStudios.SimpleRESTServices.Client;usingnet.openstack.Core.Domain;usingnet.openstack.Providers.Rackspace;namespaceTempURL{classProgram{staticvoidMain(string[]args){varregion="{region}";// See https://github.com/openstacknetsdk/openstack.net/wiki/Connect-and-Authenticate#example for how to authenticate against OpenStack instead of Rackspace.varuser=newCloudIdentity{Username="{username}",APIKey="{apikey}"};varcloudfiles=newCloudFilesProvider(user);// Create or initialize your account's key used to generate temp urlsconststringaccountTempUrlHeader="Temp-Url-Key";varaccountMetadata=cloudfiles.GetAccountMetaData(region);stringtempUrlKey;if(!accountMetadata.ContainsKey(accountTempUrlHeader)){tempUrlKey=Guid.NewGuid().ToString();varupdateMetadataRequest=newDictionary<string,string>{{accountTempUrlHeader,tempUrlKey}};cloudfiles.UpdateAccountMetadata(updateMetadataRequest,region);}else{tempUrlKey=accountMetadata[accountTempUrlHeader];}// Generate a public URL for a cloud file which is good for 1 dayvarcontainerName="{container-name}";varfileName="{file-name}";varexpiration=DateTimeOffset.UtcNow+TimeSpan.FromDays(1);UritempUrl=cloudfiles.CreateTemporaryPublicUri(HttpMethod.GET,containerName,fileName,tempUrlKey,expiration,region);}}}
Containers cannot be nested, however you can simulate subdirectories by using URL path separators in the object name. In the example below, the object name is thumbnails/tiny-logo.png and the resulting public URL of the file is: http://abc123.r27.cf1.rackcdn.com/thumbnails/logo.png.
usingSystem;usingnet.openstack.Core.Domain;usingnet.openstack.Providers.Rackspace;namespaceCloudFileSubdirectories{publicclassProgram{publicstaticvoidMain(){// Authenticateconststringregion="DFW";varuser=newCloudIdentity{Username="username",APIKey="apikey"};varcloudfiles=newCloudFilesProvider(user);// Create a containercloudfiles.CreateContainer("images",region:region);// Make the container publically accessiblelongttl=(long)TimeSpan.FromMinutes(15).TotalSeconds;cloudfiles.EnableCDNOnContainer("images",ttl,region);varcdnInfo=cloudfiles.GetContainerCDNHeader("images",region);stringcontainerPrefix=cdnInfo.CDNUri;// Upload a file to a "subdirectory" in the containercloudfiles.CreateObjectFromFile("images",@"C:\tiny-logo.png","thumbnails/logo.png",region:region);// Print out the URL of the fileConsole.WriteLine($"Uploaded to {containerPrefix}/thumbnails/logo.png");// Uploaded to http://abc123.r27.cf1.rackcdn.com/thumbnails/logo.png}}}
##Troubleshooting
Error:The user does not have access to the requested service or region.
There is a possibility that default region is not set for your account. Try passing in the optional region parameter.
For example:
cloudFileProvider.ListContainers(region: “DFW”);