Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/*
* Copyright 2021 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.google.appengine.api.blobstore.dev;
import static com.google.appengine.repackaged.com.google.common.io.BaseEncoding.base64Url;
import com.google.appengine.api.blobstore.BlobInfo;
import com.google.appengine.api.blobstore.BlobKey;
import com.google.appengine.tools.development.ApiProxyLocal;
import com.google.appengine.tools.development.Clock;
import com.google.apphosting.utils.servlet.MultipartMimeUtils;
import com.google.appengine.repackaged.com.google.common.base.Ascii;
import com.google.appengine.repackaged.com.google.common.collect.ImmutableList;
import com.google.appengine.repackaged.com.google.common.io.Closeables;
//
import java.io.BufferedReader;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.security.AccessController;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.security.PrivilegedActionException;
import java.security.PrivilegedExceptionAction;
import java.security.SecureRandom;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Date;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.activation.DataHandler;
import javax.activation.DataSource;
import javax.mail.BodyPart;
import javax.mail.MessagingException;
import javax.mail.internet.ContentType;
import javax.mail.internet.MimeMultipart;
import javax.mail.internet.ParseException;
import javax.servlet.ReadListener;
import javax.servlet.ServletException;
import javax.servlet.ServletInputStream;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletRequestWrapper;
import javax.servlet.http.HttpServletResponse;
/**
* {@code UploadBlobServlet} handles blob uploads in the development
* server. The stub implementation of {@link
* com.google.appengine.api.blobstore.BlobstoreService#createUploadUrl}
* returns URLs that are mapped to this servlet.
*
*
Its primary responsibility is parsing multipart/form-data or
* multipart/mixed requests made by web browsers. To minimize
* dependencies in the SDK, it does using the MimeMultipart class
* included with JavaMail.
*
*
After the files are extracted from the multipart request body,
* they are assigned {@code BlobKey} values and are committed to local
* storage. The multipart body parts are then replaced with
* message/external-body parts that specify the {@link BlobKey} as
* additional parameters in the Content-type header.
*
*/
public final class UploadBlobServlet extends HttpServlet {
private static final long serialVersionUID = -813190429684600745L;
private static final Logger logger =
Logger.getLogger(UploadBlobServlet.class.getName());
static final String UPLOAD_HEADER = "X-AppEngine-BlobUpload";
static final String UPLOADED_BLOBKEY_ATTR = "com.google.appengine.api.blobstore.upload.blobkeys";
static final String UPLOADED_BLOBINFO_ATTR =
"com.google.appengine.api.blobstore.upload.blobinfos";
static final String UPLOAD_TOO_LARGE_RESPONSE =
"Your client issued a request that was too large.";
static final String UPLOAD_BLOB_TOO_LARGE_RESPONSE =
UPLOAD_TOO_LARGE_RESPONSE +
" Maximum upload size per blob limit exceeded.";
static final String UPLOAD_TOTAL_TOO_LARGE_RESPONSE =
UPLOAD_TOO_LARGE_RESPONSE +
" Maximum total upload size limit exceeded.";
private BlobStorage blobStorage;
private BlobInfoStorage blobInfoStorage;
private BlobUploadSessionStorage uploadSessionStorage;
private SecureRandom secureRandom;
private ApiProxyLocal apiProxyLocal;
@Override
public void init() throws ServletException {
super.init();
blobStorage = BlobStorageFactory.getBlobStorage();
blobInfoStorage = BlobStorageFactory.getBlobInfoStorage();
uploadSessionStorage = new BlobUploadSessionStorage();
secureRandom = new SecureRandom();
apiProxyLocal = (ApiProxyLocal) getServletContext().getAttribute(
"com.google.appengine.devappserver.ApiProxyLocal");
}
@Override
public void doPost(final HttpServletRequest req, final HttpServletResponse resp)
throws ServletException, IOException {
try {
AccessController.doPrivileged(new PrivilegedExceptionAction