# UploadedFilesService.loadRemote custom logic

```ts
if (!body.data?.url)
  throw new exceptions.UnprocessableEntityException("URL required");
const {
  data: { url },
} = body;
const uploadedFilesService = Container.get(UploadedFilesService);
const {
  data: [record],
} = await uploadedFilesService.list({ filters: { remote_url: url } }, authData);
if (record) {
  scenario.set({ found: true, record });
  const file = path.join(__dirname, "../../", record.file_path);
  if (fs.existsSync(file)) {
    scenario.log();
    return { data: record };
  }
}

scenario.set({ found: false });

const folder = `uploads/${authData?.current?.user?._id ?? "unknown"}/`;
const folderPath = path.join(__dirname, `../../`, folder);
fs.mkdirSync(folderPath, { recursive: true });

const ext = getFileExtensionFromUrl(url);
const filename = `remote.${Date.now()}.${crypto.randomUUID()}${ext ? `.${ext}` : ""}`;

const destination = path.join(folderPath, filename);

scenario.set({ destination });

await downloadRemoteFile(url, destination);

const mimetype: string = mime.lookup(destination) || "application/octet-stream";
const stats = fs.statSync(destination);

let data: Partial<EntityAlias> = {};
/**
 * Auto-fill system data
 */
data.app = authData?.current?.app?._id
  ? authData?.current?.app?._id
  : authData?.current?.service?.name && !authData?.current?.service?.is_external
  ? data.app
  : undefined;
data.created_by = authData?.current?.user?._id;

if (!data.attributes) data.attributes = {};

data = {
  ...data,
  remote_url: url,
  original_name: "remote",
  file_name: "remote",
  file_path: `${folder}${filename}`,
  destination: folder,
  field_name: "remote",
  mimetype: mimetype,
  size: stats.size,
};

data.snapshots = await uploadedFilesService._generateSnapshotsObject(
  data,
  null,
  authData
);
const doc = await this.uploadedFileModel.create(data);

result = {
  data: mapDocumentToExposed(doc),
};
```
