@studiohyperdrive/strapi-plugin-media
Advanced tools
Comparing version 0.0.4 to 0.0.5
'use strict'; | ||
const path = require("path"); | ||
/** | ||
@@ -32,2 +34,3 @@ * Media.js controller | ||
const { id } = ctx.request.params; | ||
const host = strapi.config.uploadHost ? strapi.config.uploadHost : `://${strapi.config.host}:${strapi.config.port}`; | ||
@@ -37,4 +40,4 @@ let file = await strapi.plugins["media"].services.file.fetchOne(id); | ||
ctx.body = Object.assign({}, file, { | ||
url: file.url ? `://${strapi.config.host}:${strapi.config.port}${file.url}` : '', | ||
thumbnail: file.thumbnail ? `://${strapi.config.host}:${strapi.config.port}${file.thumbnail}` : '', | ||
url: file.url ? path.join(host, file.url) : '', | ||
thumbnail: file.thumbnail ? path.join(host, file.thumbnail) : '', | ||
}); | ||
@@ -41,0 +44,0 @@ }, |
{ | ||
"name": "@studiohyperdrive/strapi-plugin-media", | ||
"version": "0.0.4", | ||
"version": "0.0.5", | ||
"description": "This is the description of the plugin.", | ||
@@ -5,0 +5,0 @@ "strapi": { |
@@ -15,12 +15,18 @@ # Strapi plugin | ||
### 2. set upload path in config | ||
### 2. set upload path (& base) in config | ||
Add `uploadPath` in custom config (`custom.json`): | ||
Add custom config in `custom.json`: | ||
``` | ||
{ | ||
"uploadPath": "/public/uploads" | ||
"uploadPath": "/public/uploads", | ||
"uploadBase": "https://my-server-url/", | ||
"uploadPublicPath": "/uploads", | ||
} | ||
``` | ||
**uploadPath**: location to store files on the server (defaults to `/public/uploads`) | ||
**uploadBase**: url prefix for uploaded files in case strapi is hosted on a custom url (defaults to strapi host) | ||
**uploadPublicPath**: public path where uploaded files can be found (defaults to `uploads`) | ||
### 3. adjust request data limit | ||
@@ -27,0 +33,0 @@ |
@@ -13,3 +13,6 @@ const Q = require("q"); | ||
fs.writeFile(`${strapi.config.uploadPath}/${file.filename}`, data, writeErr => { | ||
const uploadPath = strapi.config.uploadPath || "/public/uploads"; | ||
const publicPath = strapi.config.uploadPublicPath || "/uploads"; | ||
fs.writeFile(path.join(uploadPath, file.filename), data, writeErr => { | ||
if (writeErr) { | ||
@@ -20,3 +23,3 @@ return d.reject(writeErr); | ||
d.resolve({ | ||
url: `/uploads/${file.filename}`, | ||
url: path.join(publicPath, file.filename), | ||
}); | ||
@@ -23,0 +26,0 @@ }); |
Sorry, the diff of this file is too big to display
846579
4705
44