Using require("uxp").storage always returns an empty object


#1

Hi,

I have searched the forum a bit and I did see a post about the local file storage not being available to the public (["localStorage" and "sessionStorage" will not ship to the public in October]) I’m not sure if that is related or not.

Every time I do a check on .storage or .localFileSystem they return an empty object {}.

Any good resources or tips you can share would be awesome!

Best regards
Rob.


#2

Hi @RobMehew,

localStorage and sessionStorage are common Browser properties that are not available in XD. However, I think what you are asking / need is different from that. If you are looking for a way to store files locally, using require("uxp").storage.localFileSystem is still the recommended way. If you are looking for a sample, take a look at https://github.com/AdobeXD/plugin-samples/tree/279ca7d965cd0b5f055d7e1deff8974b3b2ec075/how-to-export-a-rendition. Please let us know if you still run into any problems.


#3

Thanks for the link, I’ll give it a shot and see how I go :slight_smile:

I did think I was making the wrong connection with localStorage and sessionStorage, my bad!


#4

Oops I should of mentioned I’m looking at trying to access pluginData folder to save settings for my plugin. If there are any examples around for that specifically that would be awesome, but I’m going to go through the link you sent too :slight_smile:


#5

I think what you meant is the plugin folder not pluginData. Take a look at this line of this example: https://github.com/AdobeXD/plugin-samples/blob/86bbfa2865bffec2035b33dda3511e0861d8ac7f/e2e-colorize-text/dialogs.js#L30


#6

Thank you, I’ll take a look.

I was looking at: https://adobexdplatform.com/plugin-docs/reference/uxp/storage-index.html inside the second code block there is a reference to

const pluginDataFolder = await fs.getDataFolder();

Which is what I meant by pluginData, I forgot the folder bit, oops!

Thanks for the help :slight_smile:


#7

What I think I’m not understanding is that everything appears to be returning a lot of empty objects.

{ localFileSystem: {},
  domains: 
   { userDesktop: {},
     userDocuments: {},
     userPictures: {},
     userVideos: {},
     userMusic: {},
     appLocalData: {},
     appLocalLibrary: {},
     appLocalCache: {},
     appLocalShared: {},
     appLocalTemporary: {},
     appRoamingData: {},
     appRoamingLibrary: {} },
  types: { file: {}, folder: {} },
  formats: { utf8: {}, binary: {} },
  modes: { readOnly: {}, readWrite: {} },
  fileTypes: 
   { text: [ 'txt', 'md' ],
     images: [ 'png', 'gif', 'bmp', 'jpg' ],
     all: [ '*' ] },
  errors: 
   { AbstractMethodInvocationError: [Function: b],
     ProviderMismatchError: [Function: b],
     EntryIsNotAnEntryError: [Function: b],
     EntryIsNotAFolderError: [Function: b],
     EntryIsNotAFileError: [Function: b],
     NotAFileSystemError: [Function: b],
     OutOfSpaceError: [Function: b],
     PermissionDeniedError: [Function: b],
     EntryExistsError: [Function: b],
     FileIsReadOnlyError: [Function: b],
     DomainNotSupportedError: [Function: b],
     InvalidFileNameError: [Function: b] } }

Is this normal if you console.log uxp ?


#8

Yes, that’s normal. The current debug console can only log enumerable properties, so if there is none present, it shows as an empty object. The future debugger will be much better than this! (expected to be available XD 20/21)


#9

Just to update, managed to get everything working as intended, thanks for the help!