Skip to main content
Version: 1.0

Folder shared with custom key

Use this code if you want to share a folder, doesn't care too much about its security, and want the key part of the URL to be readable. You just need to find a 22 character string ending with A, Q, g or w. Example: if you set the key to be 'MidnightBlueCrayonDraw' then you will get a URL like https://mega.nz/#F!Example!MidnightBlueCrayonDraw. Other example keys are "DeepSeaTreasureHunting" and "AudiblenessClapperclaw". You can generate more readable keys using this tool.

You can try by running this code at your console:

deno run https://mega.js.org/demos/custom-key-shared-folder-demo.js
import { getLoggedInStorage } from './logging-in-demo.js'
const storage = await getLoggedInStorage()

console.log('Choose one of the following folders:')
console.log(storage.root.children.map(e => e.name))

const filename = prompt('Enter a folder name (case sensitive):')
const file = storage.find(filename)
if (!file) throw Error('File not found!')
if (!file.children) throw Error("That's not a folder!")

let key
for (let i = 0; i < 3; i++) {
console.log('Choose a key:')
console.log('(22 character string ending with A, Q, g or w)')
const choosenKey = prompt('>')
if (choosenKey && choosenKey.match(/^[A-Za-z\-_]{21}[AQgw]$/)) {
key = choosenKey
break
} else {
console.log('Invalid key')
}
}
if (!key) {
console.log('Key not choosen after three tries, using demo key:')
key = 'MidnightBlueCrayonDraw'
}
const link = await file.link({ key })
console.log(link)