Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: PinataCloud/pinata
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v1.10.1
Choose a base ref
...
head repository: PinataCloud/pinata
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: main
Choose a head ref
  • 2 commits
  • 4 files changed
  • 1 contributor

Commits on Dec 16, 2024

  1. Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature.
    Copy the full SHA
    ca9eb56 View commit details

Commits on Dec 17, 2024

  1. Copy the full SHA
    bfc218a View commit details
Showing with 100 additions and 96 deletions.
  1. +12 −1 CHANGELOG.md
  2. +0 −26 examples/next-starter/app/api/key/route.ts
  3. +19 −0 examples/next-starter/app/api/url/route.ts
  4. +69 −69 examples/next-starter/app/page.tsx
13 changes: 12 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -2,7 +2,18 @@

All notable changes to this project will be documented in this file.

## [1.10.0]
## [1.10.1] - 2024-12-16

### 🐛 Bug Fixes

- Updated filename parameter for creating signed upload urls

### ⚙️ Miscellaneous Tasks

- Updated resumable uploads to accept presigned urls
- Version bump

## [1.10.0] - 2024-12-16

### 🚀 Features

26 changes: 0 additions & 26 deletions examples/next-starter/app/api/key/route.ts

This file was deleted.

19 changes: 19 additions & 0 deletions examples/next-starter/app/api/url/route.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { type NextRequest, NextResponse } from "next/server";
import { pinata } from "@/utils/config";

export const dynamic = "force-dynamic";

export async function GET(req: NextRequest, res: NextResponse) {
try {
const url = await pinata.upload.createSignedURL({
expires: 30,
});
return NextResponse.json({ url: url }, { status: 200 });
} catch (error) {
console.log(error);
return NextResponse.json(
{ text: "Error creating API Key:" },
{ status: 500 },
);
}
}
138 changes: 69 additions & 69 deletions examples/next-starter/app/page.tsx
Original file line number Diff line number Diff line change
@@ -4,78 +4,78 @@ import { useState } from "react";
import { pinata } from "@/utils/config";

export default function Home() {
const [file, setFile] = useState<File>();
const [url, setUrl] = useState("");
const [uploading, setUploading] = useState(false);
const [file, setFile] = useState<File>();
const [url, setUrl] = useState("");
const [uploading, setUploading] = useState(false);

// Client side upload
//
const uploadFile = async () => {
try {
if (!file) {
alert("No file selected");
return;
}
setUploading(true);
const keyRequest = await fetch("/api/key", {
method: "GET",
});
const keyData = await keyRequest.json();
const upload = await pinata.upload.file(file).key(keyData.JWT);
const urlReuest = await fetch("/api/sign", {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({ cid: upload.cid }),
});
const url = await urlReuest.json();
setUrl(url);
setUploading(false);
} catch (e) {
console.log(e);
setUploading(false);
alert("Trouble uploading file");
}
};
// Client side upload
//
const uploadFile = async () => {
try {
if (!file) {
alert("No file selected");
return;
}
setUploading(true);
const signedUrlReq = await fetch("/api/url", {
method: "GET",
});
const signedUrlRes = await signedUrlReq.json();
const upload = await pinata.upload.file(file).url(signedUrlRes.url);
const urlReuest = await fetch("/api/sign", {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({ cid: upload.cid }),
});
const url = await urlReuest.json();
setUrl(url);
setUploading(false);
} catch (e) {
console.log(e);
setUploading(false);
alert("Trouble uploading file");
}
};

// Server side Upload
// Server side Upload

// const uploadFile = async () => {
// try {
// if (!file) {
// alert("No file selected");
// return;
// }
// setUploading(true);
// const data = new FormData();
// data.set("file", file);
// const uploadRequest = await fetch("/api/files", {
// method: "POST",
// body: data,
// });
// const signedUrl = await uploadRequest.json();
// console.log(signedUrl);
// setUrl(signedUrl);
// setUploading(false);
// } catch (e) {
// console.log(e);
// setUploading(false);
// alert("Trouble uploading file");
// }
// };
// const uploadFile = async () => {
// try {
// if (!file) {
// alert("No file selected");
// return;
// }
// setUploading(true);
// const data = new FormData();
// data.set("file", file);
// const uploadRequest = await fetch("/api/files", {
// method: "POST",
// body: data,
// });
// const signedUrl = await uploadRequest.json();
// console.log(signedUrl);
// setUrl(signedUrl);
// setUploading(false);
// } catch (e) {
// console.log(e);
// setUploading(false);
// alert("Trouble uploading file");
// }
// };

const handleChange = (e: React.ChangeEvent<HTMLInputElement>) => {
setFile(e.target?.files?.[0]);
};
const handleChange = (e: React.ChangeEvent<HTMLInputElement>) => {
setFile(e.target?.files?.[0]);
};

return (
<main className="w-full min-h-screen m-auto flex flex-col justify-center items-center">
<input type="file" id="file" onChange={handleChange} />
<button disabled={uploading} onClick={uploadFile}>
{uploading ? "Uploading..." : "Upload"}
</button>
{url && <img src={url} alt="Image from Pinata" />}
</main>
);
return (
<main className="w-full min-h-screen m-auto flex flex-col justify-center items-center">
<input type="file" id="file" onChange={handleChange} />
<button disabled={uploading} onClick={uploadFile}>
{uploading ? "Uploading..." : "Upload"}
</button>
{url && <img src={url} alt="Image from Pinata" />}
</main>
);
}