+ try {
+ $storage->put($image->path, $data);
+ } catch (Exception $e) {
+ throw new ImageUploadException(trans('errors.path_not_writable', ['filePath' => $image->path]));
+ }
+
+ return $image;
+ }
+
+ /**
+ * Gets an image from url and saves it to the database.
+ * @param $url
+ * @param string $type
+ * @param bool|string $imageName
+ * @return mixed
+ * @throws \Exception
+ */
+ private function saveNewFromUrl($url, $type, $imageName = false)
+ {
+ $imageName = $imageName ? $imageName : basename($url);
+ $imageData = file_get_contents($url);
+ if ($imageData === false) {
+ throw new \Exception(trans('errors.cannot_get_image_from_url', ['url' => $url]));
+ }
+ return $this->saveNew($imageName, $imageData, $type);
+ }
+
+ /**
+ * Saves a new image
+ * @param string $imageName
+ * @param string $imageData
+ * @param string $type
+ * @param int $uploadedTo
+ * @return Image
+ * @throws ImageUploadException
+ */
+ private function saveNew($imageName, $imageData, $type, $uploadedTo = 0)
+ {
+ $storage = $this->getStorage();
+ $secureUploads = setting('app-secure-images');
+ $imageName = str_replace(' ', '-', $imageName);
+
+ if ($secureUploads) {
+ $imageName = str_random(16) . '-' . $imageName;
+ }